2011-06-01 11 views
1

我正在爲Web應用程序使用帶有Richfaces 4.0.0.Final的JSF2.0。我有一個即時通訊使用導航。當我點擊樹中的一個節點時,我的selectionListener應該導航到與該節點相關的頁面。但是當我點擊一個節點時,我得到一個NullPointerException:<rich:tree> Node上的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和一個dds幾個實例,並覆蓋了toString方法。

任何幫助,非常感謝!

-Doug Costa

回答

4

我設法讓我的應用程序工作。我添加了rowKeyConverter="org.richfaces.IntegerSequenceRowKeyConverter"到我的<rich:tree這似乎已經解決了這個問題,並正在調用我的選擇監聽器。

相關問題