Search code examples
jsfrichfaces

<rich:tree> NullPointerException on Node Click


I am using JSF2.0 with Richfaces 4.0.0.Final for a web application. I have a im using for navigation. When I click on a node in the tree my selectionListener should navigate me to the page associated with that node. But when I click on a node I get a NullPointerException:

SEVERE: java.lang.NullPointerException
javax.faces.FacesException: java.lang.NullPointerException
    at org.richfaces.component.UIDataAdaptor.invokeOnComponent(UIDataAdaptor.java:1124)
    at org.richfaces.renderkit.TreeRendererBase.decode(TreeRendererBase.java:208)
    at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:787)
    at org.richfaces.component.UIDataAdaptor.processDecodes(UIDataAdaptor.java:824)
    at org.richfaces.context.PartialViewExecuteVisitCallback.visit(PartialViewExecuteVisitCallback    .java:55)
    at org.richfaces.context.BaseExtendedVisitContext.invokeVisitCallback(BaseExtendedVisitContext.java:337)
    at org.richfaces.component.UIDataAdaptor.visitTree(UIDataAdaptor.java:1235)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
    at javax.faces.component.UIForm.visitTree(UIForm.java:344)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
    at org.richfaces.context.ExtendedPartialViewContextImpl.executeComponents(ExtendedPartialViewContextImpl.java:249)
    at org.richfaces.context.ExtendedPartialViewContextImpl.processPartialExecutePhase(ExtendedPartialViewContextImpl.java:229)
    at org.richfaces.context.ExtendedPartialViewContextImpl.processPartial(ExtendedPartialViewContextImpl.java:208)
    at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931)
    at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
    at org.richfaces.model.ClassicTreeNodeDataModelImpl.setupChildContext(ClassicTreeNodeDataModelImpl.java:49)
    at org.richfaces.model.ClassicTreeNodeDataModelImpl.setupChildContext(ClassicTreeNodeDataModelImpl.java:35)
    at org.richfaces.model.NodesTreeSequenceKeyModel.setupKey(NodesTreeSequenceKeyModel.java:47)
    at org.richfaces.model.TreeSequenceKeyModel.setRowKey(TreeSequenceKeyModel.java:49)
    at org.richfaces.component.UIDataAdaptor.setRowKey(UIDataAdaptor.java:277)
    at org.richfaces.component.UIDataAdaptor.invokeOnComponent(UIDataAdaptor.java:1111)
    ... 43 more

I have no clue what is causing this error.

Here is my code:

xhtml:

<h:form id="richSideBarForm" >
        <rich:tree  id="richTreeBar" value="#{richTree.rootNode}"  var="node" toggleType="client" selectionType="ajax" nodeType="#{node.type}"
                 iconExpanded="/resources/images/FolderOpen_web.png" iconCollapsed="/resources/images/FolderClosed_web.png"
                 iconLeaf="/resources/images/Worksheet_web_mini.png" selectionChangeListener="#{richTree.processTreeSelectionChange}">
            <rich:treeNode id="rootNode" type="folder" iconExpanded="/resources/images/FolderOpen_web.png" iconCollapsed="/resources/images/FolderClosed_web.png">
                <h:outputText id="rootNodeOutput" value="#{node}" />
            </rich:treeNode>
            <rich:treeNode id="leafNode" type="leaf" iconLeaf="/resources/images/Worksheet_web_mini.png"  >
                <h:outputText id="leafNodeOutput" value="#{node}" />
            </rich:treeNode>
            <rich:treeNode id="leafNode" type="location" iconExpanded="/resources/images/HOME_webHI.png" iconCollapsed="/resources/images/HOME_webHI.png" >
                <h:outputText id="leafNodeOutput" value="#{node}" />
            </rich:treeNode>
        </rich:tree>
    </h:form>

I dont know if it is important but the navigation tree is part of one xhtml file which is being included in my template using a tag

BackingBean:

public class RichTree implements Serializable, TreeSelectionChangeListener{

private TreeNode rootNode;
private UITree treeBinding;

public RichTree() {
    rootNode = new TreeNodeImpl();
    loadTree();
}

/**
 * @return the rootNode
 */
public TreeNode getRootNode() {
    return rootNode;
}

public void setRootNode(TreeNode rootNode) {
    this.rootNode = rootNode;
}

private void loadTree() {
    AGOTreeNode summaryNode = new AGOTreeNode();
    summaryNode.setLabel("0000000001");
    getRootNode().addChild(0, summaryNode);
    AGOTreeNode childNode = new AGOTreeNode();
    childNode.setLabel("Node1");
    childNode.setNavigation("page1");
    summaryNode.addChild(0, childNode);
    childNode = new AGOTreeNode();
    childNode.setLabel("Node2");
    childNode.setNavigation("page2";
    summaryNode.addChild(1, childNode);
}

@Override
public void processTreeSelectionChange(TreeSelectionChangeEvent tsce) throws AbortProcessingException {
    List<Object> selection = new ArrayList<Object>(tsce.getNewSelection());
    Object currentSelectionKey = selection.get(0);
    UITree tree = (UITree) tsce.getSource();
    tree.setRowKey(currentSelectionKey);
    AGOTreeNode node = (AGOTreeNode) tree.getRowData();
    String nav= node.getNavigation();
    FacesContext fc = FacesContext.getCurrentInstance();
    fc.getApplication().getNavigationHandler().handleNavigation(fc, "", nav);
}

AGOTreeNode extends TreeNodeImpl and adds a few feilds and also overwrites the toString method.

Any Help is greatly appreciated!

-Doug Costa


Solution

  • I managed to get my application working. I added rowKeyConverter="org.richfaces.IntegerSequenceRowKeyConverter" to my <rich:tree which seems to have overcome the issue and is calling my selection listener.