6 Replies Latest reply on Feb 10, 2011 5:56 AM by veerendra nallapaneni

    Re: RichFaces Tree example is not working

    veerendra nallapaneni Newbie

      Hi, I am working on richfaces tree example. I am getting this Exception. Please help me to fix this issue.

       

      This is the code:

       

      <?xml version='1.0' encoding='UTF-8' ?>

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml"

            xmlns:h="http://java.sun.com/jsf/html"

            xmlns:f="http://java.sun.com/jsf/core"

            xmlns:a4j="http://richfaces.org/a4j"

            xmlns:rich="http://richfaces.org/rich">

          <head>

       

       

              <title>RichFaces Tree</title>

              <style type="tetext/css" >

                  .col, .col2 {

                      width:50%;

                      vertical-align:top;

                  }

              </style>

       

       

          </head>

          <body>

              <f:view>

                  <h:form>

                      <h:outputText value="Config Tree:" />

                      <h:panelGrid columns="2" width="100" columnClasses="col1,col2">

                          <rich:tree style="width:300px" nodeSelectListener="#{simpleTreeBean1.processSelection}"

                                     reRender="selectedNode"

                                     ajaxSubmitSelection="true"

                                     switchType="client"

                                     value="#{simpleTreeBean1.treeNode}"

                                     var="item">

                          </rich:tree>

                          <h:outputText escape="false" value="Selected Node: #{simpleTreeBean1.nodeTitle}" id="selectedNode" />

                      </h:panelGrid>

                  </h:form>

              </f:view>

          </body>

      </html>

       

       

       

       

      Managed Bean:

       

      package com.cassidian.tree;

       

      import java.io.IOException;

      import java.io.InputStream;

      import java.util.ArrayList;

      import java.util.Iterator;

      import java.util.List;

      import java.util.Map;

      import java.util.Properties;

       

       

      import javax.faces.FacesException;

      import javax.faces.bean.ManagedBean;

      import javax.faces.component.UIComponent;

      import javax.faces.context.ExternalContext;

      import javax.faces.context.FacesContext;

       

       

      import org.richfaces.component.UITree;

      import org.richfaces.component.html.HtmlTree;

      import org.richfaces.event.NodeSelectedEvent;

      import org.richfaces.model.TreeNode;

      import org.richfaces.model.TreeNodeImpl;

       

       

      @ManagedBean

      public class SimpleTreeBean1 {

       

       

          private TreeNode rootNode = null;

          private List<String> selectedNodeChildren = new ArrayList<String>();

          private String nodeTitle = null;

          private static final String DATA_PATH = "simple-tree-data.properties";

       

       

          private void addNodes(String path, TreeNode node, Properties properties) {

              boolean end = false;

              int counter = 1;

       

       

              while (!end) {

                  String key = path != null ? path + '.' + counter : String.valueOf(counter);

       

       

                  String value = properties.getProperty(key);

                  if (value != null) {

                      TreeNodeImpl nodeImpl = new TreeNodeImpl();

                      nodeImpl.setData(value);

                      node.addChild(new Integer(counter), nodeImpl);

                      addNodes(key, nodeImpl, properties);

                      counter++;

                  } else {

                      end = true;

                  }

              }

          }

       

       

          private void loadTree() {

              FacesContext facesContext = FacesContext.getCurrentInstance();

              ExternalContext externalContext = facesContext.getExternalContext();

              System.out.println("DATA_PATH: "+ DATA_PATH);

              InputStream dataStream = externalContext.getResourceAsStream(DATA_PATH);

              try {

                  Properties properties = new Properties();

                  properties.load(dataStream);

       

       

                  rootNode = new TreeNodeImpl();

                  addNodes(null, rootNode, properties);

       

       

              } catch (IOException e) {

                  throw new FacesException(e.getMessage(), e);

              } finally {

                  if (dataStream != null) {

                      try {

                          dataStream.close();

                      } catch (IOException e) {

                          externalContext.log(e.getMessage(), e);

                      }

                  }

              }

          }

       

       

          public void processSelection(NodeSelectedEvent event) {

              HtmlTree tree = (HtmlTree) event.getComponent();

              nodeTitle = (String) tree.getRowData();

              selectedNodeChildren.clear();

              TreeNode currentNode = tree.getModelTreeNode(tree.getRowKey());

       

       

       

       

              if (currentNode.isLeaf()) {

                  System.out.println("current tree node is a leaf");

                  selectedNodeChildren.add((String) currentNode.getData());

              } else {

                  System.out.println("current tree node is not a leaf");

       

       

                  Iterator<Map.Entry<Object, TreeNode>> it = currentNode.getChildren();

                  while (it != null && it.hasNext()) {

                      Map.Entry<Object, TreeNode> entry = it.next();

                      selectedNodeChildren.add(entry.getValue().getData().toString());

                  }

              }

          }

       

       

          public TreeNode getTreeNode() {

              if (rootNode == null) {

       

                  loadTree();

       

              }

       

       

              return rootNode;

          }

       

       

          public String getNodeTitle() {

              return nodeTitle;

          }

       

       

          public void setNodeTitle(String nodeTitle) {

              this.nodeTitle = nodeTitle;

          }

      }

       

       

       

      I am getting the Exception:

       

      SEVERE: Error Rendering View[/index.xhtml]

      javax.el.ELException: /index.xhtml @29,43 value="#{simpleTreeBean1.treeNode}": java.lang.NullPointerException

              at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)

              at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)

              at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)

              at javax.faces.component.UIData.getValue(UIData.java:554)

              at org.ajax4jsf.component.UIDataAdaptorBase.getValue(UIDataAdaptorBase.java:1647)

              at org.richfaces.component.UITree.createDataModel(UITree.java:679)

              at org.ajax4jsf.component.UIDataAdaptorBase.getExtendedDataModel(UIDataAdaptorBase.java:621)

              at org.ajax4jsf.component.UIDataAdaptorBase.setRowKey(UIDataAdaptorBase.java:339)

              at org.richfaces.renderkit.TreeRendererBase.writeContent(TreeRendererBase.java:688)

              at org.richfaces.renderkit.TreeRendererBase.encodeChildren(TreeRendererBase.java:629)

              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)

              at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:287)

              at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)

              at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)

              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)

              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)

              at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)

              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)

              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)

              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)

              at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:594)

              at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)

              at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)

              at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)

              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

              at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)

              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)

              at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)

              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)

              at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)

              at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)

              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)

              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)

              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)

              at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)

              at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)

              at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)

              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)

              at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)

              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)

              at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:239)

              at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)

              at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)

              at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)

              at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)

              at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)

              at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)

              at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)

              at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)

              at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)

              at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)

              at com.sun.grizzly.ContextTask.run(ContextTask.java:69)

              at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)

              at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)

              at java.lang.Thread.run(Thread.java:662)

      Caused by: java.lang.NullPointerException

              at java.util.Properties$LineReader.readLine(Properties.java:418)

              at java.util.Properties.load0(Properties.java:337)

              at java.util.Properties.load(Properties.java:325)

              at com.cassidian.tree.SimpleTreeBean1.loadTree(SimpleTreeBean1.java:66)

              at com.cassidian.tree.SimpleTreeBean1.getTreeNode(SimpleTreeBean1.java:108)

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

              at java.lang.reflect.Method.invoke(Method.java:597)

              at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)

              at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)

              at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)

              at com.sun.el.parser.AstValue.getValue(AstValue.java:116)

              at com.sun.el.parser.AstValue.getValue(AstValue.java:163)

              at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)

              at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)

              ... 58 more

       

       

      WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception

      java.lang.NullPointerException

              at java.util.Properties$LineReader.readLine(Properties.java:418)

              at java.util.Properties.load0(Properties.java:337)

              at java.util.Properties.load(Properties.java:325)

              at com.cassidian.tree.SimpleTreeBean1.loadTree(SimpleTreeBean1.java:66)

              at com.cassidian.tree.SimpleTreeBean1.getTreeNode(SimpleTreeBean1.java:108)

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

              at java.lang.reflect.Method.invoke(Method.java:597)

              at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)

              at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)

              at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)

              at com.sun.el.parser.AstValue.getValue(AstValue.java:116)

              at com.sun.el.parser.AstValue.getValue(AstValue.java:163)

              at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)

              at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)

              at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)

              at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)

              at javax.faces.component.UIData.getValue(UIData.java:554)

              at org.ajax4jsf.component.UIDataAdaptorBase.getValue(UIDataAdaptorBase.java:1647)

              at org.richfaces.component.UITree.createDataModel(UITree.java:679)

              at org.ajax4jsf.component.UIDataAdaptorBase.getExtendedDataModel(UIDataAdaptorBase.java:621)

              at org.ajax4jsf.component.UIDataAdaptorBase.setRowKey(UIDataAdaptorBase.java:339)

              at org.richfaces.renderkit.TreeRendererBase.writeContent(TreeRendererBase.java:688)

              at org.richfaces.renderkit.TreeRendererBase.encodeChildren(TreeRendererBase.java:629)

              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)

              at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:287)

              at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)

              at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)

              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)

              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)

              at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)

              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)

              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)

              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)

              at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:594)

              at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)

              at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)

              at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)

              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

              at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)

              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)

              at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)

              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)

              at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)

              at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)

              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)

              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)

              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)

              at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)

              at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)

              at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)

              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)

              at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)

              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)

              at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:239)

              at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)

              at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)

              at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)

              at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)

              at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)

              at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)

              at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)

              at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)

              at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)

              at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)

              at com.sun.grizzly.ContextTask.run(ContextTask.java:69)

              at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)

              at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)

              at java.lang.Thread.run(Thread.java:662)

        • 1. Re: RichFaces Tree example is not working
          Mark Paluch Master

          Hi Veerendra,

          the problem is that your Properties-File simple-tree-data.properties is not found in the Webapp-Folder. Try to put it in your sources-Dir and access it thru getClass().getResourceAsStream(DATA_PATH);

           

          Best regards,

          Mark

          • 2. Re: RichFaces Tree example is not working
            veerendra nallapaneni Newbie

            Hello Mr. Mark,

             

            Thank you for the reply. I have placed the simple-tree-data.properties file under WEB-INF. Still I am getting the same exception. I have also checked it in classes folder, The file is there in class path.

             

            I am using NetBeans 6.9.1, RichFaces 3.3.3, GlassFish 3.0.1

             

            I need to develop a tree with context menu (add a node, edit a node, delete a node). I got stuck with this issue. Please point me to some tree example with context menu.

             

            I don't want to load the tree from properties file. I need to get it from database. I am using JPA to connect to my PostgreSQL.

             

             

            Thank you.

            • 3. Re: RichFaces Tree example is not working
              Sreejith PS Newbie

              Hi Veerendra,

               

              If you find the null pointer exception is while reading the properties file and if you are unable to read the file even when it is present in your class path, you can try another way to read the properties file.

               

              Keep an entry in faces config

               

              <application>

                   <message-bundle>simple-tree-data.properties</message-bundle>

              </application>

               

              In your java class method put the following code slice,

               

              String DATA_PATH = "simple-tree-data.properties";

              ResourceBundle bundle = ResourceBundle.getBundle(DATA_PATH);

               

              This will solve the issue.

               

              Thanks & Regards,

              Sreejith

              1 of 1 people found this helpful
              • 4. Re: RichFaces Tree example is not working
                Mark Paluch Master

                Ok,

                if your simple-tree-data.propertie is under WEB-INF, the DATA_PATH must be "/WEB-INF/simple-tree-data.properties" when you go with externalContext.getResourceAsStream(DATA_PATH) on the File.

                 

                Best regards,

                Mark

                • 5. Re: RichFaces Tree example is not working
                  veerendra nallapaneni Newbie

                  Hi Sreejith,

                   

                  Thank you for the reply.

                  I have added message-bundle to faces config. Still the problem is not fixed.

                   

                  SEVERE: Error Rendering View[/index.xhtml]

                  javax.el.ELException: /index.xhtml @28,43 value="#{simpleTreeBean1.treeNode}": java.lang.NullPointerException

                          at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)

                          at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)

                   

                   

                    at java.lang.Thread.run(Thread.java:662)

                  Caused by: java.lang.NullPointerException

                          at java.util.Properties$LineReader.readLine(Properties.java:418)

                          at java.util.Properties.load0(Properties.java:337)

                          at java.util.Properties.load(Properties.java:325)

                          at com.cassidian.tree.SimpleTreeBean1.loadTree(SimpleTreeBean1.java:64)

                          at com.cassidian.tree.SimpleTreeBean1.getTreeNode(SimpleTreeBean1.java:106)

                          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                          at java.lang.reflect.Method.invoke(Method.java:597)

                          at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)

                   

                   

                  Thank you.

                   

                  NetBeans 6.9.1, RichFaces 3.3.3, GlassFish 3.0.1

                  • 6. Re: RichFaces Tree example is not working
                    veerendra nallapaneni Newbie

                    Hi Mark,

                     

                    Thank you very much. I am able to see the tree now.

                     

                    Can you please help me on adding and deleting tree nodes dynamically.

                     

                    Thank you.