我的环境是:Primefaces 5.1; jdk 7.0.40; JSF 2.0(Mojarra 2.03-FCS); Tomcat 7.0。 我构建了一个p:selectOneListbox和p:contextMenu:一切正常。问题是:如果尚未执行任何选择,如何检索列表中的哪个项目触发了contextMenu(右键单击时正确显示)?
<h:form id="recipeFilesForm">
<h:outputText value="Recipe files" style="position:relative;left:40px;font-size:0.9em;" />
<p:selectOneListbox id="recipeFileList" value="#{RecipeFormMngr0.selecteduserFileIndex}"
style="width:190px;font-size:0.7em;text-align:left;position:relative;left:-24px">
<f:selectItems value="#{RecipeFormMngr0.recipeFileNamesItems}" var="u" itemLabel="#{u.label}" itemValue="#{u.value}">
</f:selectItems>
<p:ajax event="click" listener="#{RecipeFormMngr0.selecteduserFileIndexSelected}" />
</p:selectOneListbox>
<p:contextMenu for="recipeFileList" style="font-size:0.7em;">
<p:menuitem value="Show" actionListener="#{RecipeFormMngr0.showRecipeContent}" ajax="true" process=":loginForm0_1:userSettingTab:recipeFilesForm" />
<p:menuitem value="Delete" actionListener="#{RecipeFormMngr0.deleteRecipeFile}" ajax="true" process=":loginForm0_1:userSettingTab:recipeFilesForm" />
<p:menuitem value="Edit" actionListener="#{RecipeFormMngr0.editRecipeContent}" ajax="true" process=":loginForm0_1:userSettingTab:recipeFilesForm" />
</p:contextMenu>
</h:form>