3 Replies Latest reply on Mar 20, 2007 7:13 AM by Marcin M

    seam & facelets & tree component & strange java.lang.ClassCa

    Marcin M Newbie

      Anyone knows what am I doing wrong?

      I have one simple stateful bean which passes root node to tree component. When i try to display the page i'm redirected to seam debug page and get following exception

      20:01:59,011 ERROR [STDERR] Mar 19, 2007 8:01:59 PM com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View[/tree.xhtml]
      java.lang.ClassCastException: richtest.tree.TreeNodeExample
       at org.richfaces.component.AbstractTreeDataModel.setWrappedData(AbstractTreeDataModel.java:63)
       at org.richfaces.component.UITree.createDataModel(UITree.java:477)
       at org.ajax4jsf.ajax.repeat.UIDataAdaptor.getExtendedDataModel(UIDataAdaptor.java:464)
       at org.ajax4jsf.ajax.repeat.UIDataAdaptor.setRowKey(UIDataAdaptor.java:280)
       at org.ajax4jsf.ajax.repeat.UIDataAdaptor.setRowKey(UIDataAdaptor.java:265)
       at org.richfaces.renderkit.TreeRendererBase.writeContent(TreeRendererBase.java:395)
       at org.richfaces.renderkit.TreeRendererBase.encodeChildren(TreeRendererBase.java:299)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:524)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:244)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:249)
       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:249)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:573)
       at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
       at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:229)
       at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:384)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:234)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
       at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
       at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:96)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:220)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:595)
      


      I checked what is AbstractTreeDataModel.setWrappedData responsilble for:

       public final void setWrappedData(Object data) {
       wrappedData = (TreeNode) data;
       }
      


      so, I have put a breakpoint there and checked what Object data appear to be. As expected it was my implementation of TreeNode.

      package richtest.tree;
      
      import java.util.HashMap;
      import java.util.Iterator;
      import java.util.Map;
      
      import org.richfaces.component.TreeNode;
      
      public class TreeNodeExample implements TreeNode {
      
       /**
       *
       */
       private static final long serialVersionUID = 1L;
      
       private Map<Object, TreeNode> childs;
      
       private TreeNode parent;
      
       private String name;
      
       public TreeNodeExample() {
       childs = new HashMap<Object, TreeNode>();
      
       }
      
       public TreeNodeExample(String name) {
       this();
       this.name = name;
      
       }
      
       public TreeNodeExample(String name, TreeNode parent) {
       this(name);
       setParent(parent);
      
       }
      
       public void addChild(Object id, TreeNode child) {
       getChilds().put(id, child);
      
       }
      
       public int getChildsSize() {
       return getChilds().size();
       }
      
       private Map<Object, TreeNode> getChilds() {
       return this.childs;
       }
      
       public TreeNode getChild(Object id) {
       return (TreeNode) getChilds().get(id);
       }
      
       public Iterator getChildren() {
       return getChilds().entrySet().iterator();
       }
      
       public Object getData() {
      
       return this;
       }
      
       public TreeNode getParent() {
       return parent;
       }
      
       public boolean isLeaf() {
       return getChilds().isEmpty();
       }
      
       public void removeChild(Object id) {
       TreeNode tmp = getChild(id);
       tmp.setParent(null);
       getChilds().remove(id);
      
       }
      
       public void setData(Object arg0) {
       // not used
      
       }
      
       public void setParent(TreeNode parent) {
       if (parent != null) {
       TreeNodeExample ex = (TreeNodeExample) parent;
       parent.addChild(ex.getChildsSize(), this);
       }
       this.parent = parent;
      
       }
      
       public String getName() {
       return name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
      
       public String toString() {
       return name;
       }
      
      }
      


      my page:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <div xmlns="http://www.w3.org/1999/xhtml"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich"
       xmlns:a4j="https://ajax4jsf.dev.java.net/ajax">
      
      
       <ui:composition template="/template.xhtml">
      
       <ui:define name="body">
       <f:view>
       <h:form>
       <div>
      
       <rich:tree width="300" height="150"
       value="#{treeExample.data}" var="item" nodeFace="test">
       <rich:treeNode type="test">
       <h:outputText value="#{item.name}" />
       </rich:treeNode>
       </rich:tree>
      
       </div>
      
       </h:form>
       </f:view>
       </ui:define>
       </ui:composition>
      
      </div>
      


      the template
      <?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:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich">
       <head>
       <meta http-equiv="Content-Type"
       content="text/html; charset=iso-8859-1" />
       <meta http-equiv="expires" content="0" />
       <title>Test</title>
      
       <style type="text/css">
      /* a lot of classes */
      </style>
      
       </head>
      
       <body>
      
       <h:form>
       <rich:toolBar itemSeparator="line">
       <rich:toolBarGroup itemSeparator="grid">
      
       <h:commandLink value="simple" action="/slider.seam" />
       <h:commandLink value="tree" action="/tree.seam" />
       <h:commandLink value="table" action="/table.seam" />
       </rich:toolBarGroup>
      
       </rich:toolBar>
       </h:form>
       <ui:insert name="body">
       TOPNAV
       </ui:insert>
       </body>
      </html>
      
      


      and the stateful bean

      package richtest.tree;
      
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.Name;
      
      @Stateful
      @Name("treeExample")
      public class TreeManager implements ITreeManager {
      
       private TreeNodeExample root;
      
       @Remove
       @Destroy
       public void destroy() {
      
       }
      
       public Object getData() {
       if (root == null)
       init();
      
       return root;
       }
      
       private void init() {
      
       this.root = new TreeNodeExample("root");
       for (int i = 0; i < 6; i++) {
       TreeNodeExample item = new TreeNodeExample("item" + i, root);
       }
      
      
       }
      }
      
      
      


      with it's inteface

      package richtest.tree;
      
      import javax.ejb.Local;
      
      
      @Local
      public interface ITreeManager {
      
       public void destroy();
      
      
      
       public Object getData();
      }
      
      


      please, help ;)

        • 1. Re: seam & facelets & tree component & strange java.lang.Cla
          Nick Belaevski Master

          Hello!

          That can happen if classes were loaded by different class loaders. Can you please check that?

          What application server are you using?

          • 2. Re: seam & facelets & tree component & strange java.lang.Cla
            Marcin M Newbie

             

            "nbelaevski" wrote:
            Hello!

            That can happen if classes were loaded by different class loaders. Can you please check that?

            What application server are you using?


            JBoss AS 4.0.5 GA.

            I have looked at my configuration files and .ear file structure and I don't see any potential problems with class loaders. Could you, please, check it?

            faces-config.xml

            <?xml version="1.0" encoding="UTF-8"?>
            <!-- JSF 1.1 -->
            <!DOCTYPE faces-config
             PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
             "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
            <faces-config>
             <lifecycle>
             <phase-listener>
             org.jboss.seam.jsf.TransactionalSeamPhaseListener
             </phase-listener>
             </lifecycle>
            </faces-config>
            


            web.xml

            <?xml version="1.0" encoding="UTF-8"?>
            <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
            
             <!-- Ajax4jsf (must come first!) -->
            
             <filter>
             <display-name>Ajax4jsf Filter</display-name>
             <filter-name>ajax4jsf</filter-name>
             <filter-class>org.ajax4jsf.Filter</filter-class>
             </filter>
            
             <filter-mapping>
             <filter-name>ajax4jsf</filter-name>
             <url-pattern>*.seam</url-pattern>
             </filter-mapping>
            
             <context-param>
             <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
             <param-value>
             org.jboss.seam.ui.facelet.SeamFaceletViewHandler
             </param-value>
             </context-param>
             <filter-mapping>
            
             <filter-name>ajax4jsf</filter-name>
            
             <servlet-name>Faces Servlet</servlet-name>
            
             <dispatcher>REQUEST</dispatcher>
            
             <dispatcher>FORWARD</dispatcher>
            
             <dispatcher>INCLUDE</dispatcher>
            
             </filter-mapping>
            
             <context-param>
            
             <param-name>org.ajax4jsf.SKIN</param-name>
            
             <param-value>blueSky</param-value>
            
             </context-param>
             <!-- Seam -->
            
             <listener>
             <listener-class>
             org.jboss.seam.servlet.SeamListener
             </listener-class>
             </listener>
            
             <servlet>
             <servlet-name>Seam Resource Servlet</servlet-name>
             <servlet-class>
             org.jboss.seam.servlet.ResourceServlet
             </servlet-class>
             </servlet>
            
             <servlet-mapping>
             <servlet-name>Seam Resource Servlet</servlet-name>
             <url-pattern>/seam/resource/*</url-pattern>
             </servlet-mapping>
            
             <filter>
             <filter-name>Seam Filter</filter-name>
             <filter-class>org.jboss.seam.web.SeamFilter</filter-class>
             </filter>
            
             <filter-mapping>
             <filter-name>Seam Filter</filter-name>
             <url-pattern>/*</url-pattern>
             </filter-mapping>
            
             <!-- JSF -->
            
             <context-param>
             <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
             <param-value>client</param-value>
             </context-param>
            
             <context-param>
             <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
             <param-value>.xhtml</param-value>
             </context-param>
            
             <context-param>
             <param-name>facelets.DEVELOPMENT</param-name>
             <param-value>true</param-value>
             </context-param>
            
             <servlet>
             <servlet-name>Faces Servlet</servlet-name>
             <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
             <load-on-startup>1</load-on-startup>
             </servlet>
            
             <servlet-mapping>
             <servlet-name>Faces Servlet</servlet-name>
             <url-pattern>*.seam</url-pattern>
             </servlet-mapping>
            
             <!-- MyFaces -->
             <listener>
             <listener-class>
             org.apache.myfaces.webapp.StartupServletContextListener
             </listener-class>
             </listener>
            </web-app>
            
            


            the structed of ear [as I see it in Eclipse]

            RichFaces.ear
            |+ richfaces-3.0.0.jar
            |+ jboss-seam.jar
            |+ lib
             |+ ajax4jsf-1.1.0.jar
             |+ el-api.jar
             |+ el-ri.jar
             |+ jbpm-3.1.4.jar
             |+ oscache.jar
            |+RichFacesEJB.jar
             |+ ajax4jsf-1.1.0.jar
             |+ el-api.jar
             |+ el-ri.jar
             |+ jbpm-3.1.4.jar
             |+ oscache.jar
             |+ richfaces-3.0.0.jar
             |+ jboss-seam.jar
             |+hibernate-all.jar
             |+ jboss-ejb3-all.jar
            |+ RichFacesWeb.war
             |+ WEB-INF
             |+ lib
             |+ ajax4jsf-1.1.0.jar
             |+ el-api.jar
             |+ el-ri.jar
             |+ oscache.jar
             |+ richfaces-3.0.0.jar
             |+ jboss-seam-ui.jar
             |+ jboss-seam-debug.jar
             |+ jsf-facelets.jar
             |+ standart.jar
             |+ jboss-seam.jar
             |+ jstl.jar
            


            • 3. Re: seam & facelets & tree component & strange java.lang.Cla
              Marcin M Newbie

              I have edited the server/default/deploy/jbossweb-tomcat55.sar/META-INF/jboss-service.xml

              and changed Java2ClassLoadingCompliance and UseJBossWebLoader from false to true, and suddenly, the error disappeared.