Tree collapse and expand problem

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

10 Sep 2019, 23:18

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
                            1.1.1.1. Room 1
                            1.1.1.2 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>  
					        			
		<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>
Session Bean:

Code: Select all

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

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

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

			closeForm();
			buildDepartmentInfoString();
			determineSubmitStatus();

			ReportController rc = (ReportController) FacesContext
					.getCurrentInstance().getExternalContext().getSessionMap()
					.get("reportController");
			rc.calculateCountOfAssignees();

			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
					
					//SS--118
					if (treeNode.isExpanded()) 
						treeNode.setExpanded(false);
					else
						treeNode.setExpanded(true);
					
					List<Building> buildings = new SurveyDataModel().getBuildingsForSurvey(((Department)treeNode.getData()).getSpaceSurvey());
					
					// put the buildings on the survey
					((Department)treeNode.getData()).getSurvey().setBuildingsAndIds(buildings);
					
					// 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
				
			context.update("treePrime");
		} 
   ................
}


Exception:

9/10/19
2:14:27.000 PM Caused by: javax.faces.FacesException: java.lang.NullPointerException at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:273) at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57) at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:927) at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78) ... 30 more Caused by: java.lang.NullPointerException at org.primefaces.component.tree.Tree.queueEvent(Tree.java:340) at org.primefaces.behavior.ajax.AjaxBehaviorRenderer.decode(AjaxBehaviorRenderer.java:47) at javax.faces.component.behavior.ClientBehaviorBase.decode(ClientBehaviorBase.java:132) at org.primefaces.renderkit.CoreRenderer.decodeBehaviors(CoreRenderer.java:553) at org.primefaces.component.tree.TreeRenderer.decode(TreeRenderer.java:62) at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:832) at org.primefaces.component.tree.Tree.processDecodes(Tree.java:405) at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:573) at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) at org.primefaces.component.api.UITree.visitTree(UITree.java:738) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at javax.faces.component.UIForm.visitTree(UIForm.java:362) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403) at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:266) ... 33 more

Primefaces 6.0
JSF 2.2
Tomcat 7

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

11 Sep 2019, 13:07

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?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

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

11 Sep 2019, 17:33

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?

https://github.com/primefaces/primeface ... tion-Guide

many thanks!
Primefaces 6.0
JSF 2.2
Tomcat 7

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

11 Sep 2019, 22:29

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: https://github.com/primefaces/primeface ... dated-desc
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

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

11 Sep 2019, 23:07

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(PartialViewContextImpl.java:273

Your help is greatly appreciated.
Primefaces 6.0
JSF 2.2
Tomcat 7

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

12 Sep 2019, 12:55

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.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

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

12 Sep 2019, 16:31

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.
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 35 guests