I have some problems when trying to use a contextmenu on a selectable datatable. (PF 5)
My contextmenu has to display some information for the selected row.
If I select something with a left click and then right click on the same row there is no problem. The row is selected first and with the right click the context menu is shown with the correct data.
If I select something directly with a right click, the "rowSelect" event is not fired BUT the selected row is changed visibly (highlighted) and the selectedObject is changed too.
So the context menu will call the doCopy and doRemove methods with the changed object (as it should do) but the visible contents of the context menu are wrong (the old object). The result is that it shows the id and name of one object and removes another...
Furthermore it seems that the context menu is not updated with the "onstart"-call at the right time. It only flashes and disappears with the _old_ data. With the next right click the data will be updated (but the context menu will disappear again... the contextMenu-event with the remoteCommand was a try after I recognised that the rowSelect-event was not called).
I think with the "onstart"-parameter the update should be called before the contextMenu is shown? Or how is it possible to update the data in the contextMenu _before_ it is shown at all?
Code: Select all
<h:form id="myForm">
<p:remoteCommand name="updateCM" update=":myForm:fullcontextmenu"/>
<p:contextMenu id="fullcontextmenu" for="fulltable" widgetVar="fullcontextwidget">
<p:menuitem value="#{myBean.selectedObject.id} - #{myBean.selectedObject.name}" disabled="true"/>
<p:separator/>
<p:menuitem value="Copy" actionListener="#{myBean.doCopy(myBean.selectedObject)}" update=":myForm"/>
<p:menuitem value="Remove" actionListener="#{myBean.doRemove(myBean.selectedObject)}" update=":myForm"/>
</p:contextMenu>
<p:dataTable id="fulltable"
value="#{myBean.objectList}"
var="myObject"
selectionMode="single"
selection="#{myBean.selectedObject}"
rowKey="#{myObject.id}">
<p:ajax event="contextMenu" onstart="updateCM()"/>
<p:ajax event="rowSelect"
listener="#{myBean.doSomethingOnSelection('string_parameter')}"
oncomplete="doSomethingCallback(xhr,status,args)"
update=":myForm:fullcontextmenu"/>
<f:facet name="header">
<p:outputLabel value="My Table Header"/>
</f:facet>
<p:column>
<h:outputText value="#{myObject.name}"/>
</p:column>
</p:dataTable>
</h:form>