I'm using PrimeFaces 5.3.
Setter for myBean.selectedNode is not invoked when right clicking the node in the example below.
<h:form id="mainForm">
<p:tree value="#{myBean.root}" var="node"
id="myTree" dynamic="true"
selectionMode="single" selection="#{myBean.selectedNode}">
<p:treeNode expandedIcon="ui-icon-folder-open" collapsedIcon="ui-icon-folder-collapsed"
type="myType">
<h:outputText value="#{node}"/>
</p:treeNode>
<p:ajax event="select" listener="#{myBean.onNodeSelect}" />
</p:tree>
<p:contextMenu for="myTree">
<p:menuitem action="#{myBean.addChild('new')}"
value="Add"
process="@this"
update=":mainForm:myTree"/>
</p:contextMenu>
</h:form>
I'm still not sure if this is a bug or that I'm doing something wrong. Maybe it's related to the select listener, but without it it was also not working for me.
Anyhow, I was able to get it to work by replacing the tree's nodeRightClick function:
PrimeFaces.widget.BaseTree.prototype.nodeRightClick = function(e, a) {
PrimeFaces.clearSelection();
if ($(e.target).is(":not(.ui-tree-toggler)")) {
var d = a.parent(), b = a.hasClass("ui-tree-selectable");
if (b && this.cfg.selectionMode) {
var c = this.isNodeSelected(d);
if (!c) {
if (this.isCheckboxSelection()) {
this.toggleCheckboxNode(d)
} else {
this.unselectAllNodes();
// Fixed right click selecting
// original code: this.selectNode(d, true)
this.selectNode(d); // <-- Fix
}
}
this.fireContextMenuEvent(d)
}
}
}
Please use contextMenu event.
I'm puzzled. I've checked the tree and contextMenu section of the documentation twice. What event should be used where?
@mertsincan
The 5.3 docs state:
Ajax Behavior Events
Tree provides various ajax behavior events.
| Event | Listener Parameter | Fired |
| --- | --- | --- |
| expand | org.primefaces.event.NodeExpandEvent | When a node is expanded. |
| collapse | org.primefaces.event.NodeCollapseEvent | When a node is collapsed. |
| select | org.primefaces.event.NodeSelectEvent | When a node is selected. |
| unselect | org.primefaces.event.NodeUnselectEvent | When a node is unselected. |
There is no contextMenu event in the docs but there is in the 5.3 code. Please create a new issue to update this as well as for the dragDrop event!!!
@jepsar: title is wrong... it is not 'selection' but 'ajax selection event'. that is the difference with the showcase. So your original title was right