Tree collapse event issue in PrimeFaces 7

UI Components for JSF
Post Reply
jenni03
Posts: 26
Joined: 21 Jul 2010, 20:53

24 Sep 2021, 17:55

Hello,

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"/>&nbsp;<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>
     			
Hope you can help shed some light on this issue. BTW, we don't have time to upgrade to the newer version of the Primefaces library as we have our project deadline scheduled already.
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
Primefaces 6.0
JSF 2.2
Tomcat 7

Melloware
Posts: 2856
Joined: 22 Apr 2013, 15:48

25 Sep 2021, 00:39

I would check PF 8.0 or 10.0 to see if it is still an issue. If not its most likely already been fixed along the way.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 10.0.7 / PF Extensions 10.0.6

jenni03
Posts: 26
Joined: 21 Jul 2010, 20:53

25 Sep 2021, 19:36

Thanks for your reply! I've tried PF 8.0, but it has the same Ajax event behaviour as PF 7. In another word, the collapse listener method will not be triggered unless the tree cache value is set to "false".
My question is we have to use PF 7 with the non-cache-tree component, do you foresee lots of performance problems?

Is this a bug brought in PF 7 since PF 6 works well when the cache value is set to "true"?
Primefaces 6.0
JSF 2.2
Tomcat 7

Melloware
Posts: 2856
Joined: 22 Apr 2013, 15:48

26 Sep 2021, 17:03

I would search the GitHub issues list to see why the behavior changed between PF6 and PF7. My guess is some fix was done that caused this.

Something like this: https://github.com/primefaces/primefaces/issues/3668

Or this: https://github.com/primefaces/primefaces/issues/5409
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 10.0.7 / PF Extensions 10.0.6

jenni03
Posts: 26
Joined: 21 Jul 2010, 20:53

26 Sep 2021, 23:20

I looked into the following two posts that you provided and I got confused about the comments as below specified in the tickets. It seems that the collapse event is not called on purpose when cache = true for a dynamic tree, right?

So the only solution for the problem encountered in our use case is that we have to set cache = false in order to call the collapsed event, right? Or in other words, we can't keep the expanded tree nodes in memory in order to avoid the problem we had in testing, correct?

Your help is much appreciated!

in 6.3, we will have:
expand and collapse events will be fired always, doesn't matter if dynamic true or false
BUT
expand and collapse will both NOT be fired when cache=true; expand will just be fired for the initial request to get the sub-nodes to cache

NOTE: cache=true is the default

applying the PR is a performance loss


Indeed, I'm sorry but I published the wrong code. The tree should be dynamic and the update should not be there. I corrected the code above and tested it against version 8.0.RC1 of Primefaces and "collapsed" event is not called.
Primefaces 6.0
JSF 2.2
Tomcat 7

Melloware
Posts: 2856
Joined: 22 Apr 2013, 15:48

28 Sep 2021, 14:28

That is how I interpreted it as well. It was done on purpose.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 10.0.7 / PF Extensions 10.0.6

jenni03
Posts: 26
Joined: 21 Jul 2010, 20:53

28 Sep 2021, 23:24

Got it. Thanks very much for your reply!
Primefaces 6.0
JSF 2.2
Tomcat 7

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 28 guests