Our project has been upgraded from PrimeFaces 6 to PrimeFaces 7 recently, however, we encountered a problem after testing for the Upgraded project. We have a tree structure to represent different departments, each department tree node has child tree nodes to refer to building/floor/room in a hierarchy order.
The use case we used in testing is as follows:
(1) Open a department tree node and expand the parent node to the room level in a hierarchy order as below
department->building->floor->room
(2) Close the department tree node.
(3) Open another department tree node and expand it to the room level.
(4) Select the current department's room tree node to display detailed room information.
(5) This selection will trigger the previous department's node and all of the children node displayed again in the tree.
This problem happens only in the PrimeFaces 7 environment. After searching forum posts, I came across a post below talking about a possible solution. I added code in the collapse listener method "onNodeCollapse" below to setExpanded value to false in the collapse event handler.
The weird thing is that the listener method is NOT triggered if I use cache="true" in the <p:tree> component. After I change the cache value to "false", the listener method can be triggered.
Even though the issue we encountered can be solved in this change, this is not an ideal solution since we can't keep the expanded tree node in memory. This will cause performance issues in our application.
viewtopic.php?f=3&t=32032&p=101964#p101964
Code: Select all
public void onNodeCollapse(NodeCollapseEvent event) {
LOGGER.error("Inside onNodeCollapse method: ");
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Collapsed<br />", event.getTreeNode().toString());
TreeNode treeNode = event.getTreeNode();
String nodetype = treeNode.getType();
if (event != null && event.getTreeNode() != null) {
event.getTreeNode().setExpanded(false);
}
}
<p:tree selectionMode="single" selection="#{deptFacilitiesTree.selectedNode}" value="#{deptFacilitiesTree.root}"
var="node" id="treePrime" cache="false" dynamic="true" >
<p:ajax event="select" listener="#{facilitiesController.onNodeSelect}"/>
<p:ajax event="expand" listener="#{facilitiesController.onNodeExpand}" />
<p:ajax event="collapse" listener="#{facilitiesController.onNodeCollapse}" />
<p:ajax event="unselect" listener="#{facilitiesController.onNodeUnselect}" />
<p:treeNode type="organization" icon="#{node.survey.treeIcon}" >
<h:outputText value="#{node.departmentName}" escape="false"/>
</p:treeNode>
<p:treeNode type="building" icon="#{node.treeIcon}">
<h:outputText value="#{node.bldg}" escape="false"/> <h:outputText value="#{node.description}" escape="false"/>
</p:treeNode>
<p:treeNode type="floor" icon="#{node.treeIcon}">
<h:outputText value="#{node.description}" escape="false"/>
</p:treeNode>
<p:treeNode type="room" icon="#{node.treeIcon}">
<h:outputText value="#{node.locationCode}"/>, <h:outputText value="#{node.locTypeDescription}" escape="false"/>
</p:treeNode>
</p:tree>
Is there any workaround for this problem?
How much impact for the application's performance if we have to use cache="false" in this dynamic tree?
In the following migration guide 6.0 to 6.1, it specifies changes to include rowKey in the Tree API. This is the only change from for the libraries upgraded from primefaces 6 to 7 to tree component. Does this anything to do with the tree collapse event?
DefaultTreeNode equals/hashCode has been changed to include the rowKey, this could break your code. See: https://github.com/primefaces/primefaces/issues/1433
Thanks for your time! Your help is much appreciated!
Jenny
JSF 2.3
Primefaces 7.0
JDK 11