Tree & contextMenu & rightclickselection
cbensemann Mar 10, 2010 8:04 PMHi,
There have been numerous posts on the forums about adding context menus to trees but I have got myself totally lost and cannot get this to work the way I want.
What I would like to happen:
When a user right clicks on a node or leaf on the tree the node is selected and then the context menu is shown for the user which has options to add new nodes or edit the existing (selected one)
I have attempted various things but here is the code as I think it should work:
<rich:tree id="allCorrectiveActionsTree" toggleOnClick="true" ajaxKeys="#{null}" rightClickSelection="true" ajaxSubmitSelection="true" nodeSelectListener="#{manageCorrectiveActionsController.processSelection}" dropListener="#{manageCorrectiveActionsController.dropListener}" dragIndicator="indicator"> <rich:recursiveTreeNodesAdaptor roots="#{root}" nodes="#{caTreeNode.children}" var="caTreeNode"> <rich:treeNodesAdaptor nodes="#{caTreeNode.correctiveActions}" var="action"> <rich:treeNode dragType="leaf"> <h:outputText id="leafLabel" value="#{action.title}" /> <rich:dndParam name="label" value="#{action.title}" type="drag" /> <rich:contextMenu submitMode="none"> <rich:menuItem value="#{messages.button_delete}" onclick="#{rich:component('deleteConfirmationPanel')}.show();" /> </rich:contextMenu> </rich:treeNode> </rich:treeNodesAdaptor> <rich:treeNode id="nodeNode" icon="/a4j/g/3_3_3.CR1images/iconFolder.gif" iconLeaf="/a4j/g/3_3_3.CR1images/iconFolder.gif" acceptedTypes="node, leaf" dragType="node"> <h:outputText id="nodeLabel" value="#{caTreeNode.title}" /> <rich:dndParam name="label" value="#{caTreeNode.title}" type="drag" /> <rich:contextMenu id="nodeContextMenu" submitMode="none"> <rich:menuItem value="#{messages.manage_corrective_actions_add_new_node}" id="newNode" onclick="setSelection(event); #{rich:component('newNodePanel')}.show();" /> <rich:menuItem value="#{messages.manage_corrective_actions_add_new_leaf}" id="newLeaf" onclick="#{rich:component('newLeafPanel')}.show();" onselect="setSelection(event)" /> <rich:menuItem value="#{messages.button_delete}" id="delete" onclick="#{rich:component('deleteConfirmationPanel')}.show();" onselect="setSelection(event)" /> </rich:contextMenu> </rich:treeNode> </rich:recursiveTreeNodesAdaptor> </rich:tree>
What seems to happen is the right click selection is processed and then no menu appears. Without rightclickselection enabled the menu appears but obviously the node is not selected.
I know I'm missing something simple but I've stared at this code for a long time without being able to make it work so its time I got a second opinion.
thanks
Craig