aspose file tools*
The moose likes JSF and the fly likes JSF tree component NULL pointer exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF tree component NULL pointer exception" Watch "JSF tree component NULL pointer exception" New topic
Author

JSF tree component NULL pointer exception

Muhammad FAisal khan
Greenhorn

Joined: Dec 25, 2005
Posts: 5
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">
<hutputText 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)
 
jQuery in Action, 2nd edition
 
subject: JSF tree component NULL pointer exception
 
Similar Threads
Whether tag handlers are needed in creating a t:tree component
Problem using UI:Tree
How to work with t:tree component
JSF tree component
JSF Menu and tree components