Board index JavaServer Faces General TreeNode and DefaultTreeNode

TreeNode and DefaultTreeNode

Components, Ajax Framework, Utilities and More.

Post 24 Jun 2011, 17:54

Posts: 24
Hi,

Im trying the treetable example from the user guide but Im getting an error, can anyone help thx a lot? :)
Im using jboss seam and primefaces 1.1. the back bean is like this:

@Name("documentsController")
public class DocumentsController {
private TreeNode root;
public DocumentsController() {
root = new DefaultTreeNode("root", null);
TreeNode documents = new DefaultTreeNode("Documents", root);
TreeNode pictures = new DefaultTreeNode("Pictures", root);
TreeNode music = new DefaultTreeNode("Music", root);
TreeNode work = new DefaultTreeNode("Work", documents);
TreeNode primefaces = new DefaultTreeNode("PrimeFaces", documents);
//Documents
TreeNode expenses = new DefaultTreeNode("document", "Expenses.doc", work);
TreeNode resume = new DefaultTreeNode("document", "Resume.doc", work);
TreeNode refdoc = new DefaultTreeNode("document", "RefDoc.pages", primefaces);
//Pictures
TreeNode barca = new DefaultTreeNode("picture", "barcelona.jpg", pictures);
TreeNode primelogo = new DefaultTreeNode("picture", "logo.jpg", pictures);
TreeNode optimus = new DefaultTreeNode("picture", "optimus.png", pictures);
//Music
TreeNode turkish = new DefaultTreeNode("Turkish", music);
}
public TreeNode getRoot() {
return root;
}
}


here is the error:
java.lang.ClassCastException: org.primefaces.model.DefaultTreeNode cannot be cast to org.primefaces.model.TreeNode
at org.primefaces.component.treetable.TreeTableRenderer.encodeRows(TreeTableRenderer.java:116)
at org.primefaces.component.treetable.TreeTableRenderer.encodeMarkup(TreeTableRenderer.java:71)
at org.primefaces.component.treetable.TreeTableRenderer.encodeEnd(TreeTableRenderer.java:35)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:937)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
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:110)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
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:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)


Posts: 24
Anybody has an idea on this?
I've been struggling on this for weeks, thanks.


Posts: 24
somebody, please give me a hint, thx.

kukeltje Expert Member

Posts: 6262
Location: Netherlands
a hint... hmm.... what about multiple versions in different classloaders?
Ronald van Kuijk
______________________________
PrimeFaces 4.0, PrimeFaces plus 0.0.2 | Jboss 7.2.0 | Mojarra 2.1.18
Fedora 19, Firefox 26.0
Read the forum posting rules
Beginners: http://www.coreservlets.com/JSF-Tutorial/jsf2/


Posts: 61
Have you first try with this example : http://www.primefaces.org/showcase/ui/tree.jsf

Does it works ?

And please put your code into the code markup (edit post)
JSF 2.0
Primefaces 3.0.M3
Tomcat 7.0
--
French user of primefaces


Posts: 24
Hi, rdeoliveira

No the tree is not working. I got the same problem. Im using primefaces2.2.1
java.lang.ClassCastException: org.primefaces.model.DefaultTreeNode cannot be cast to org.primefaces.model.TreeNode
   at org.primefaces.component.tree.TreeRenderer.encodeScript(TreeRenderer.java:171)
   at org.primefaces.component.tree.TreeRenderer.encodeEnd(TreeRenderer.java:163)
   at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:937)
   at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
   at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
   at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
   at org.openfaces.ajax.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:64)
   at org.openfaces.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:413)
   at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
   at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
   at org.openfaces.ajax.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:64)
   at org.openfaces.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:413)
   at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
   at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.openfaces.util.ResourceFilter.doFilter(ResourceFilter.java:99)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
   at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
   at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
   at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
   at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
   at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
   at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
   at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
   at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
   at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
   at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
   at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
   at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
   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:235)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
   at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
   at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Unknown Source)

Oleg User avatar
Expert Member

Posts: 3702
Location: Russia, Siberia => Germany, Black Forest
The thread is old, but sometimes I see the same exception in log files:

INFO: java.lang.ClassCastException: [Lorg.primefaces.model.DefaultTreeNode; cannot be cast to org.primefaces.model.TreeNode
java.lang.ClassCastException: [Lorg.primefaces.model.DefaultTreeNode; cannot be cast to org.primefaces.model.TreeNode
   at org.primefaces.component.tree.Tree.processUpdates(Tree.java:322)
   at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:510)
   at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
   at javax.faces.component.UIComponent.visitTree(UIComponent.java:1589)


I use PF 2.2.1. Any ideas? It's really annoying because I don't see any issues with using of Tree.

P.S. buggy, buggy Tree. I had so many tree selection issues in PF 2.2.1 and now this ClassCastException.
PrimeFaces 4.x, 5.x, Mojarra 2.2.x, JBoss WildFly, WebSphere, Windows 8.1, IntelliJ IDEA
PrimeFaces Cookbook: http://ova2.github.com/primefaces-cookbook/ PrimeFaces Extensions on GitHub: http://primefaces-extensions.github.com/

Oleg User avatar
Expert Member

Posts: 3702
Location: Russia, Siberia => Germany, Black Forest
I have found the issue!

We can write selectionMode="single" and define selection as an Array of DefaultTreeNode. But Tree.java in PrimeFaces has this check:

            if(selectionMode.equals("single")) {
                if(previousSelection != null)
                    ((TreeNode) previousSelection).setSelected(false);
                if(selection != null)
                    ((TreeNode) selection).setSelected(true);
            }

Casting is always to TreeNode, not to array of TreeNode for single selection. The issue gone after I set single selection as a single DefaultTreeNode (not DefaultTreeNode[]).
PrimeFaces 4.x, 5.x, Mojarra 2.2.x, JBoss WildFly, WebSphere, Windows 8.1, IntelliJ IDEA
PrimeFaces Cookbook: http://ova2.github.com/primefaces-cookbook/ PrimeFaces Extensions on GitHub: http://primefaces-extensions.github.com/


Return to General