Page 1 of 1

Tree collapse and expand problem

Posted: 10 Sep 2019, 23:18
by jenni03
The application has an hierarchy relationship and is built by primefaces tree component. There are four types of tree nodes defined: Organization, Building, Floor and Room. The tree is built dynamically whenever user clicks a type of tree node. For e.g., if Organization type node is clicked, all of the Children nodes(Building types of nodes) is built by fetching data from database for a specific organization. When floor type of node is selected, all of the children nodes (Room type nodes) will be built. User can click expand or collapse arrows for each type of tree nodes except the room type of node.

The problem we encountered is that when user expand or collapse different types of nodes many times, the application will throw exception below. If there is not much expand or collapse actions, the tree data can be displayed correctly. It would be great if you can help shed some lights on this problem. Thanks in advance.

Code: Select all

Hierarchy Relationship Structure:
  1.0 Organization
          1.1 Building 1
                 1.1.1 4th Floor
                   Room 1
                   Room 2

           1.2 Building 2

xhtml file:

Code: Select all

 <p:tree selectionMode="single" selection="#{deptFacilitiesTree.selectedNode}" value="#{deptFacilitiesTree.root}" 
     							 var="node" id="treePrime" cache="true" 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 type="building" icon="#{node.treeIcon}">
					      <h:outputText value="#{node.bldg}" escape="false"/>&nbsp;<h:outputText value="#{node.description}" escape="false"/>
		 <p:treeNode type="floor" icon="#{node.treeIcon}">
					       <h:outputText value="#{node.description}" escape="false"/>					            			  
		<p:treeNode type="room" icon="#{node.treeIcon}">
					         <h:outputText value="#{node.locationCode}"/>, <h:outputText value="#{node.locTypeDescription}" escape="false"/>            			  
Session Bean:

Code: Select all

@ManagedBean(name = "facilitiesController")
public class FacilitiesController implements Serializable {

private void onNodeSelect(TreeNode treeNode) {
		String nodetype = treeNode.getType();
		RequestContext context = RequestContext.getCurrentInstance();
		UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
		stickyBoxInformation = "";

              if (nodetype.contentEquals("organization")) {
			currentOrganizationNode = treeNode;


			ReportController rc = (ReportController) FacesContext

			LOGGER.debug("Organization treeNode expanded: " + treeNode.isExpanded());
			// Expand/collapse appropriately on node click
			// if the survey isn't completed...
			if(!PortalConstants.TREE_COMPLETE.equals(((Department)treeNode.getData()).getSurvey().getTreeIcon())) {
					// Expand the current node and its parents
					// Department
					if (treeNode.isExpanded()) 
					List<Building> buildings = new SurveyDataModel().getBuildingsForSurvey(((Department)treeNode.getData()).getSpaceSurvey());
					// put the buildings on the survey
					// reset the children and make the tree nodes for the buildings
					((DefaultTreeNode)treeNode).setChildren(new ArrayList<TreeNode>());
					// get the buildings from the survey so they'll be sorted properly
					for(Building building : ((Department)treeNode.getData()).getSurvey().getBuildings()) {
						TreeNode buildingNode = new DefaultTreeNode("building", building, treeNode);
						// add an empty "floor" so the expand/collapse arrow shows on the building
						new DefaultTreeNode("floor", null, buildingNode);
				}//end if


2:14:27.000 PM Caused by: javax.faces.FacesException: java.lang.NullPointerException at com.sun.faces.context.PartialViewContextImpl.processPartial( at org.primefaces.context.PrimePartialViewContext.processPartial( at javax.faces.component.UIViewRoot.processDecodes( at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute( ... 30 more Caused by: java.lang.NullPointerException at org.primefaces.component.tree.Tree.queueEvent( at org.primefaces.behavior.ajax.AjaxBehaviorRenderer.decode( at javax.faces.component.behavior.ClientBehaviorBase.decode( at org.primefaces.renderkit.CoreRenderer.decodeBehaviors( at org.primefaces.component.tree.TreeRenderer.decode( at javax.faces.component.UIComponentBase.decode( at org.primefaces.component.tree.Tree.processDecodes( at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit( at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback( at org.primefaces.component.api.UITree.visitTree( at javax.faces.component.UIComponent.visitTree( at javax.faces.component.UIForm.visitTree( at javax.faces.component.UIComponent.visitTree( at javax.faces.component.UIComponent.visitTree( at com.sun.faces.context.PartialViewContextImpl.processComponents( at com.sun.faces.context.PartialViewContextImpl.processPartial( ... 33 more

Re: Tree collapse and expand problem

Posted: 11 Sep 2019, 13:07
by Melloware
I see you are on PF 6.0. Is there any way you can try a newer version like 7.0 to see if this problem hasn't already been fixed?

Re: Tree collapse and expand problem

Posted: 11 Sep 2019, 17:33
by jenni03
Thanks for your reply! I tried to get PrimeFaces 7.0 jar file for the application and noticed many new compilation errors generated after using version 7. The application was originally built on Primefaces 3.4.
We have encountered several issues need to be tackled in the migration from 3.4 to 6.0. It seems to me it will take longer time to migrate to 7.0 as many changes specified in the migration guide below.

Therefore, I would like get a better idea about this exception. Is this a bug in PrimeFaces? Did you foresee the new version 7 should fix this problem? ... tion-Guide

many thanks!

Re: Tree collapse and expand problem

Posted: 11 Sep 2019, 22:29
by Melloware
Well I can't tell but if you search for closed issues around the Tree component you will see quite a few since 6.0.

See this search for all items closed and what version it was closed in: ... dated-desc

Re: Tree collapse and expand problem

Posted: 11 Sep 2019, 23:07
by jenni03
Thanks a lot for your reply! I did see lots of defects related to tree component got fixed in newer version. Therefore, I'll try to update our code to migrate to version 7 to see if this problem can be resolved or not.

Currently, I only want to confirm with you one thing. This exception should not be caused by our application code, right? I did not see any of the classes in our application specified in the stacktraces.
So, I don't have to worry about our application code caused this runtime NPE exception below:

Caused by: javax.faces.FacesException: java.lang.NullPointerException at com.sun.faces.context.PartialViewContextImpl.processPartial(

Your help is greatly appreciated.

Re: Tree collapse and expand problem

Posted: 12 Sep 2019, 12:55
by Melloware
I can't be positive but it does feel like it is a bug in the Tree which is why I think it has been already fixed.

Re: Tree collapse and expand problem

Posted: 12 Sep 2019, 16:31
by jenni03
Thanks very much for your reply! I'm glad to know I don't have to worry about our application code may cause this exception.