1 Reply Latest reply on Jun 5, 2009 10:13 PM by Francisco Jose Peredo Noguez

    Richface Tree menu and Seam

    matt colman Newbie
      Hey guys, forgive me if this is the stupidest question you read today but I am really very new to programming as a whole. Basically, I need to have a rich:tree in my view that loads dynamically from the database. I am using the seam generated entity and list classes. When I try to load the view on the server I this in my console. Remember I am very new at java, not just seam! Thanks very much (the hibernate is actually retrieving from the database hence the stdout)

      /*INFO  STDOUT Hibernate:
          select
              appdb0_.DB_ID as DB1_10_,
              appdb0_.DB_NAME as DB2_10_,
              appdb0_.USER_ID as USER3_10_
          from
              dbman.APPDB appdb0_ limit ?
      18:44:14,744 ERROR [viewhandler] Error Rendering View[/RichTree2.xhtml]
      java.lang.ClassCastException: com.mydomain.dbtreenew.model.Appdb cannot be cast to javax.swing.tree.TreeNode
              at org.richfaces.model.SwingTreeDataModel.setWrappedData(SwingTreeDataModel.java:66)
              at org.richfaces.component.UITree.createDataModel(UITree.java:692)
              at org.ajax4jsf.component.UIDataAdaptor.getExtendedDataModel(UIDataAdaptor.java:621)
              at org.ajax4jsf.component.UIDataAdaptor.setRowKey(UIDataAdaptor.java:339)
              at org.richfaces.renderkit.TreeRendererBase.writeContent(TreeRendererBase.java:660)
              at org.richfaces.renderkit.TreeRendererBase.encodeChildren(TreeRendererBase.java:601)
              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
              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:390)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
              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:58)
              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:601)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)


      Now here is the view (nothing fancy just a tree implementation)

      <?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">
      <ui:composition 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:a4j="http://richfaces.org/a4j"
            xmlns:rich="http://richfaces.org/rich"
            xmlns:s="jboss.com/products/seam/taglib">
           
                <h:form>   
              <rich:tree style="width:300px" id="appdbList" value="#{appdbList.resultList}" var="_appdb" nodeFace="#{item.type}">
                  <rich:treeNode type="dbName">
                      <h:outputText value="#{_appdb.dbName}" />
                  </rich:treeNode>
                  <rich:treeNode type="userId">
                      <h:outputText value="#{_appdb.userId}" />
                  </rich:treeNode>
                  <rich:treeNode type="dbId">
                      <h:outputText value="#{_appdb.dbId}" />
                  </rich:treeNode>
              </rich:tree>
      </h:form>

      </ui:composition>

      Here is the entity Appdb.java, seam generated:
      @Entity
      @Table(name = "APPDB", catalog = "dbman")
      public class Appdb  {

              private Integer dbId;
              private int userId;
              private String dbName;
             
              public Appdb() {
              }

              public Appdb(int userId, String dbName) {
                      this.userId = userId;
                      this.dbName = dbName;
              }

              @Id
              @GeneratedValue(strategy = IDENTITY)
              @Column(name = "DB_ID", unique = true, nullable = false)
              public Integer getDbId() {
                      return this.dbId;
              }

              public void setDbId(Integer dbId) {
                      this.dbId = dbId;
              }

              @Column(name = "USER_ID", nullable = false)
              public int getUserId() {
                      return this.userId;
              }

              public void setUserId(int userId) {
                      this.userId = userId;
              }

              @Column(name = "DB_NAME", nullable = false, length = 30)
              @NotNull
              @Length(max = 30)
              public String getDbName() {
                      return this.dbName;
              }

              public void setDbName(String dbName) {
                      this.dbName = dbName;
              }

      }

      And here is the seam generated AppdbList.java

      @Name("appdbList")
      public class AppdbList extends EntityQuery<Appdb> {

              private static final String EJBQL = "select appdb from Appdb appdb";

              private static final String[] RESTRICTIONS = {"lower(appdb.dbName) like lower(concat(#{appdbList.appdb.dbName},'%'))",};

              private Appdb appdb = new Appdb();

              public AppdbList() {
                      setEjbql(EJBQL);
                      setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
                      setMaxResults(25);
                     
              }

              public Appdb getAppdb() {
                      return appdb;
              }
      } \*


      Sorry again if the solution is ridiculously obvious but I have been trying for ages and have looked everywhere, perhaps i just dont understand how to correctly implement a rich tree component?? Thanks for your help guys! I appreciate any! Everywhere i have read said that the tree could just read any Datamodel, and I assumed since the seam-gen program could use that information in a datatable, why can't i use it in a tree? Thanks.

      Matt