我正在使用带有 contextMenu 的树,这是代码:
<p:contextMenu id="campaignPlaneTreeContextMenu" for="campaignPlanetree" >
<p:menuitem value="New Camapign" disabled="#{projectCampaignManagementMB.campaignOptionsFlag}" />
<p:menuitem value="Assign" disabled="#{projectCampaignManagementMB.FSTOptions}" />
<p:menuitem value="Copy campaign" disabled="#{projectCampaignManagementMB.FSTOptions}"/>
<p:menuitem value="Paste Campaign" disabled="#{projectCampaignManagementMB.pasteOptionCampaignFlag}"/>
<p:menuitem value="Delete" disabled="#{projectCampaignManagementMB.FSTOptions}" />
<p:menuitem value="Import Tests" disabled="#{projectCampaignManagementMB.campaignOptionsFlag}" />
</p:contextMenu>
<p:tree id="campaignPlanetree"
value="#{projectCampaignManagementMB.root}" var="node"
selectionMode="single"
selection="#{projectCampaignManagementMB.selectedNode}"
dynamic="true">
<p:ajax event="select" listener="#{projectCampaignManagementMB.onCampaignPlaneNodeSelect}" update=":campaignForm:addCampaignBtn :campaignForm:renameCampaignBtn :campaignForm:importCampaignBtn :campaignForm:deleteCampaignBtn :campaignForm:importCampaignDlg :campaignForm:campaignPlaneTreeContextMenu" />
<p:treeNode value="#{node}">
<h:outputText value="#{node}" />
</p:treeNode>
.....
托管豆:
if(selectedNode.getData() instanceof Campaign){// when a user select a tree node the contextmenu item are disabled and enabled
setCampaignOptionsFlag(false);
....
}
如果没有 disabled 属性,一切都很好,但是添加它后,上下文菜单会立即消失。