Environment:
PrimeFaces 6.1
JSF 2.2
Tomcat 7.0.23
Java 1.7.0_79
Implemented a TreeTable with checkbox selection, and need to prevent selection propagation up and down for parent and child nodes respectively for client and server side processing.
Example Tree:
Parent Node
--Child Node 1
----Child Sub-Node 1.1
--Child Node 2
----Child Sub-Node 2.1
Desired Behavior:
When selecting a node, only that node's checkbox should be selected.
Actual Behaviour (out of the box):
Selecting a node, child and parent nodes are selected. For example, selecting Child Node 2 in above Example Tree the Parent Node and Child Sub-Node 2.1 are also selected.
TreeTable component:
<p:treeTable id="treeTable" value="#{Bean.rootNode}" var="item" selectionMode="checkbox" nodeVar="node"
styleClass="widthFull" showUnselectableCheckbox="true" selection="#{Bean.selectedNodes}" stickyHeader="true">
<p:ajax event="select" listener="#{Bean.processSelect(item)}" ignoreAutoUpdate="true"/>
<p:ajax event="unselect" listener="#{Bean.processUnselect(item)}" ignoreAutoUpdate="true"/>
....
</p:treeTable>
Overriding PrimeFaces JS functions:
Able to prevent propagation in client side processing by overriding PrimeFaces.widget.TreeTable.prototype.propagateUp and PrimeFaces.widget.TreeTable.prototype.getDescendants javascript functions.
PrimeFaces.widget.TreeTable.prototype.propagateUp = function(node) {
//do nothing, overriding the TreeTable propagate selection up functionality
}
PrimeFaces.widget.TreeTable.prototype.getDescendants = function(node) {
//do nothing other than return empty array, overriding the TreeTable propagate selection down functionality by overriding getDescendants...hopefully this doesn't cause other issues
f = [];
return f;
}
TreeTable Update:
The TreeTable update is performed as part of the ajax select and unselect event processing.
RequestContext.getCurrentInstance().update("inventoryForm:treeTable");
Question:
When the ajax select and unselect events are fired in order to disable selectability on specific nodes and updating the TreeTable, child node(s) are getting selected. The child nodes are not in the selectedNodes array on the Bean when processing the ajax event listeners. How can I prevent the child node(s) from being selected upon TreeTable component update?