3 Replies Latest reply on Jun 26, 2009 11:07 AM by matt colman

    Any help for a complete beginner, regarding a rich:tree? :):

    matt colman Newbie

      Hey guys! Firstly thank you for any help you can give me. First I will just explain that I have only been learning Java as a whole for a few months and am new to pretty much every aspect! I have been trying to get a tree menu working that loads at run time with values it pulls dynamically from the database according to the current user. The issue is actually getting the tree to display! I have looked at the exadel live demo and everything but something just is not clicking for me I guess... I have tried several approaches but generally the tree does not render at all.

      I decided to use the actual Seam generated List class similar to how it is used in a rich:datatable but when it loads the data I just get a classcastexception. I will post what I tried to do after but... I would greatly appreciate if anyone would just tell me everything that I need to do to render a dynamic tree. I'm not asking for you to write the code for me just an outline, like I will need the correct database schema, using an entityquery to pull the data from the database, then how do I get the tree to take up that data that the query has yielded?

      See I thought that the tree could accept any List object, of which AppdbList provides... It works in a rich:datatable, why not in a tree?

      Basically at the end of the day, the application needs to load the users data from the database which should look like this in a tree:
      Databases
      --Database1
      ---table x
      ---table y
      ----field x
      ----field y
      -----row x
      --Database2
      ---table x
      ----field x

      Something to that effect (the tree basically should store the layout of a database) and eventually will need to be able to perform crud operations... But that I will work out in time, the main thing for me at the moment is to get the tree to work! Here is the result when I tried to use the seam generated lists in a tree.. Thank you for your time!


      /*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 {

      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;
      }
      } \*