Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JSF tree component NULL pointer exception

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am using Facelets



Taglib configuration

<tag>
<tag-name>tree</tag-name>
<component>
<component-type>org.apache.myfaces.HtmlTree</component-type>
<renderer-type>org.apache.myfaces.HtmlTree</renderer-type>
</component>
</tag>

<tag>
<tag-name>tree2</tag-name>
<component>
<component-type>org.apache.myfaces.HtmlTree2</component-type>
<renderer-type>org.apache.myfaces.HtmlTree2</renderer-type>
</component>
</tag>
<tag>
<tag-name>treeColumn</tag-name>
<component>
<component-type>org.apache.myfaces.HtmlTreeColumn</component-type>
</component>
</tag>


Java CODE


package test.model;

import org.apache.myfaces.custom.tree.DefaultMutableTreeNode;
import org.apache.myfaces.custom.tree.model.DefaultTreeModel;

public class TreeBean {
private DefaultTreeModel tree;
private String name="yahoo";
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public DefaultTreeModel getTree() {
return tree;
}

public void setTree(DefaultTreeModel tree) {
this.tree = tree;
}

public TreeBean(){
DefaultMutableTreeNode root = new DefaultMutableTreeNode("XY");
DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
root.insert(a);
DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
root.insert(b);
DefaultMutableTreeNode c = new DefaultMutableTreeNode("C");
root.insert(c);
DefaultMutableTreeNode node = new DefaultMutableTreeNode("a1");
a.insert(node);
node = new DefaultMutableTreeNode("a2 ");
a.insert(node);
node = new DefaultMutableTreeNode("b ");
b.insert(node);
a = node;
node = new DefaultMutableTreeNode("x1");
a.insert(node);
node = new DefaultMutableTreeNode("x2");
a.insert(node);
//tree = ;
this.setTree(new DefaultTreeModel(root));
}
}

Managed Bean code
=----------------
<managed-bean>
<managed-bean-name>testAction</managed-bean-name>
<managed-bean-class>com.shma.realestate.actions.TestAction</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>

<managed-property>
<property-name>testManager</property-name>
<value>#{testManager}</value>
</managed-property>

</managed-bean>



XHTML File
----------

<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xml:lang="en" lang="en">
<body>
<ui:composition>
Hello to new jsf world
<h:form id="mainForm">
<h:outputText value="#{treeBean.name}"/>
<t:tree id="tree" modle="#{treeBean.tree}" styleClass="tree" >
</t:tree>
</h:form>
</ui:composition>
</body></html>





WHEN I EXECUTE APP IT GENERATES NULL POINTER EXCEPTION
Stack Trace:
SEVERE: Error Rendering View[/pages/welcome.xhtml]
java.lang.NullPointerException
at org.apache.myfaces.custom.tree.HtmlTree.addToModelListeners(HtmlTree.java:810)
at org.apache.myfaces.custom.tree.HtmlTree.encodeBegin(HtmlTree.java:687)
at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:232)
at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:580)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:352)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic