rich : tree // rich:tree // trying to make the basics work
wolfbenz May 12, 2008 5:26 PMHi List,
- To the Jboss guys: Cf earlier post: there is a void when it comes to doc / online material to make the rich:tree work. All the "RichFaces Reference" has to say about it, is:
HtmlTreeNode root = new HtmlTreeNode(); :-)
Therefore, an attempt (though it doesn't work, so some advice is welcome)
In my page, I do the following:
 <rich:tree switchType="client" adviseNodeOpened="true" value="#{menuBean.tree}" var="node" nodeFace= "#{node.type}" showConnectingLines="true">
 <rich:treeNode type="root" >
 <h:outputText value="#{node.attributes.name}" />
 </rich:treeNode>
 <rich:treeNode type="menuCategory" >
 <h:outputText value="#{node.attributes.name}" />
 </rich:treeNode>
 <rich:treeNode type="menuItem" >
 <h:commandLink action="#{useCaseBean.pickUseCase}" immediate="true">
 <f:param name="usecase" value="#{node.attributes.link}" />
 <h:outputText id="TreeNode" value="#{node.attributes.name}" style="font-family:verdana;"/>
 </h:commandLink>
 </rich:treeNode>
 </rich:tree>
As you have guessed, it's a menu to allow the user to choose it's use case.
In my Menu backing bean, I have:
("private HtmlTree tree" with seters and getters are set, this is the tree init() method: )
setTree(new HtmlTree()); getTree().setSwitchType("client");
 HtmlTreeNode root = new HtmlTreeNode();
 root.setType("root");
 root.getAttributes().put("name", "Use Cases");
 // Add the root node to the Tree:
 getTree().getChildren().add(root);
 // Add first menu Category to root: the "stations" category:
 HtmlTreeNode stationsMenuCat = new HtmlTreeNode();
 stationsMenuCat.setType("menuCategory");
 stationsMenuCat.getAttributes().put("name", "Stations"));
 stationsMenuCat.getAttributes().put("link", "tree_stations");
 root.getChildren().add(stationsMenuCat);
 // Add first menu Item to the station mens category: "Stations Programming"
 HtmlTreeNode stationsMenuItem = new HtmlTreeNode();
 stationsMenuItem.setType("menuItem");
 stationsMenuItem.getAttributes().put("name", "Stations Programming"));
 stationsMenuItem.getAttributes().put("link", "tree_progrStations");
 stationsMenuCat.getChildren().add(stationsMenuItem);
... This throws me an error:
java.lang.ClassCastException: org.richfaces.component.html.HtmlTree
 at org.richfaces.model.SwingTreeDataModel.setWrappedData(SwingTreeDataModel.java:75)
 at org.richfaces.component.UITree.createDataModel(UITree.java:588)
 at org.richfaces.component.UITree.resetDataModel(UITree.java:354)
 at org.ajax4jsf.component.UIDataAdaptor.encodeBegin(UIDataAdaptor.java:1176)
 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:884)
 at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
 at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:809)
 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
 at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
 at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
 at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:189)
 at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
 at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
 at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
 at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:256)
 at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:362)
 at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:488)
 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:286)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
Apart from resolving the error, I have another question:
I use the 'attributes" for being able, at the client side, to retrieve these attributes and, like shown higher, e.g. use them for a link. Is this the proper way to do this?
Or is it required to work with an HtmlOutputText or so?
Second: is the "data" var of a TreeNode just a RichFaces wrapper around the "attributes" or don't they have anything to do with each other?
Sorry for all the questions - I hope someone bothers to clear this up (with such ttle, hopefully a lot of people can use it afterwards)
Thanks in advance for help,
-Wolf
 
     
     
     
     
     
    