现在我想使用JSF树的鼠标右键菜单,就像链接的例子一样。当我单击鼠标右键时,菜单可以立即显示和消失。我不知道如何显示鼠标右键菜单(treecontext)。你能就此提出一些建议吗?感谢。
http://www.primefaces.org/showcase/ui/treeContextMenu.jsf
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:form id="treeform">
<p:tree value="#{treeBean.root}" var="node" id="tree" rendered="true" dynamic="true" cache="false" selectionMode="single" selection="#{treeBean.selectedNode}">
<p:ajax event="expand" listener="#{treeBean.onNodeExpand}"/>
<p:ajax event="collapse" listener="#{treeBean.onNodeCollapse}" />
<p:ajax event="select" listener="#{tableBean.showScenario}" update=":mainForm:scenarioDetailTable :mainForm:dynaFormGroup :mainForm:breadcrumbmenu :mainForm:accordingpanel1:treeform:tree :mainForm:accordingpanel1:treeform:treecontext" />
<p:ajax event="unselect" listener="#{treeBean.onNodeUnselect}" update=":mainForm:scenarioDetailTable :mainForm:dynaFormGroup :mainForm:breadcrumbmenu :mainForm:accordingpanel1:treeform:tree :mainForm:accordingpanel1:treeform:treecontext" />
<p:treeNode id="treeNode" rendered="true" animate="true" expandedIcon="ui-icon-folder-open" collapsedIcon="ui-icon-folder-collapsed">
<h:outputText value="#{node.name}" id="lblNode"/>
</p:treeNode>
</p:tree>
<p:contextMenu id="treecontext" for="tree" rendered="true" >
<p:menuitem value="Add Product" disabled="#{tableBean.selectedProjectNodeLevel==1?false:true}" icon="ui-icon-contact" action="#{treeBean.setDialogTitle}" update=":mainForm:scenarioDetailTable :mainForm:accordingpanel1:treeform:tree " oncomplete="PF('createproductdlg').show()" onclick="PF('createproductdlg').show()" />
<p:menuitem value="Add Capability" disabled="#{tableBean.selectedProjectNodeLevel==2?false:true}" icon="ui-icon-contact" action="#{treeBean.setDialogTitle}" update=":mainForm:scenarioDetailTable :mainForm:accordingpanel1:treeform:tree " oncomplete="PF('createcapabilitydlg').show()" onclick="PF('createcapabilitydlg').show()" />
<p:menuitem value="Add Feature" disabled="#{tableBean.selectedProjectNodeLevel>=3?false:true}" icon="ui-icon-contact" action="#{treeBean.setDialogTitle}" update=":mainForm:scenarioDetailTable :mainForm:accordingpanel1:treeform:tree " oncomplete="PF('createfeaturedlg').show()" onclick="PF('createfeaturedlg').show()" />
<p:menuitem value="Add Scenario" disabled="#{tableBean.selectedProjectNodeLevel>=3?false:true}" icon="ui-icon-contact" update=":mainForm:scenarioDetailTable :mainForm:accordingpanel1:treeform:tree " oncomplete="PF('scenariodlg').show()" onclick="PF('scenariodlg').show()" />
<p:menuitem value="Delete" update="tree" actionListener="#{treeBean.create}" icon="ui-icon-close"/>
</p:contextMenu>
</h:form>
</ui:composition>
主页代码的某些部分
<h:form id="mainForm">
<p:layout id="fulllayout" fullPage="true">
<!-- top menu start -->
<p:layoutUnit id="layoutunittop" position="north" size="50">
<p:breadCrumb id="breadcrumbmenu" rendered="true">
<p:menuitem value="Categories" url="#" />
<p:menuitem value="Project" url="#" disabled="true" />
<p:menuitem value="Add Product" disabled="#{tableBean.selectedProjectNodeLevel==1?false:true}" action="#{treeBean.setDialogTitle}" update=":mainForm:scenarioDetailTable :mainForm:accordingpanel1:treeform:tree " oncomplete="PF('createproductdlg').show()" onclick="PF('createproductdlg').show()" />
<p:menuitem value="Add Capability" disabled="#{tableBean.selectedProjectNodeLevel==2?false:true}" action="#{treeBean.setDialogTitle}" update=":mainForm:scenarioDetailTable :mainForm:accordingpanel1:treeform:tree " oncomplete="PF('createcapabilitydlg').show()" onclick="PF('createcapabilitydlg').show()" />
<p:menuitem value="Add Feature" disabled="#{tableBean.selectedProjectNodeLevel>=3?false:true}" action="#{treeBean.setDialogTitle}" update=":mainForm:scenarioDetailTable :mainForm:accordingpanel1:treeform:tree " oncomplete="PF('createfeaturedlg').show()" onclick="PF('createfeaturedlg').show()" />
<p:menuitem value="Add Scenario" disabled="#{tableBean.selectedProjectNodeLevel>=3?false:true}" update=":mainForm:scenarioDetailTable :mainForm:accordingpanel1:treeform:tree " oncomplete="PF('scenariodlg').show()" onclick="PF('scenariodlg').show()" />
</p:breadCrumb>
</p:layoutUnit>
<!-- top menu end -->
<!-- menu begin -->
<p:layoutUnit id="layoutunitleft" position="west" size="360" resizable="true" collapsible="true" header="Options" minSize="260">
<p:accordionPanel id="accordingpanel1" rendered="true" >
<p:tab id="accordingpanel1tab" title="Project">
<ui:include src="tree.xhtml" />
</p:tab>
<p:tab title="Test Set">
<h:outputText value="Test Set" />
</p:tab>
<p:tab title="Report">
<!-- <h:outputText value="Report" /> -->
<!-- <p:calendar mode="inline" navigator="none"/> -->
</p:tab>
</p:accordionPanel>
</p:layoutUnit>
<!-- menu end -->
....