节点上的<rich:tree> NullPointerException单击</rich:tree>

时间:2011-06-01 21:15:34

标签: jsf richfaces

我正在将JSF2.0与Richfaces 4.0.0.Final一起用于Web应用程序。我有一个用于导航的im。当我单击树中的节点时,我的selectionListener应该导航到与该节点关联的页面。但是当我点击一个节点时,我得到一个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

我不知道导致此错误的原因。

这是我的代码:

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>

我不知道它是否重要,但导航树是一个xhtml文件的一部分,该文件使用标签包含在我的模板中

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扩展TreeNodeImpl并添加一些字段并覆盖toString方法。

非常感谢任何帮助!

-Doug Costa

1 个答案:

答案 0 :(得分:4)

我设法让我的应用程序正常运行。我向rowKeyConverter="org.richfaces.IntegerSequenceRowKeyConverter"添加了<rich:tree,这似乎已经克服了这个问题并且正在调用我的选择监听器。