3 Replies Latest reply on May 17, 2007 8:35 PM by c_eric_ray

    Child component will not render in rich:tree

      I can't get the rich:tree component to render anything other the the very top level. I've matched the nodeFace="#{item.type}" call to the type value on rich:treeNode. I've setup all the data so the structure is good (I can print the tree and it looks correct). However, when I use the browser to render the tree, all I get is the very top level. They render as leaf nodes and the value rendered on the web page is the object id, same is if you call System.out.print(object). What gives? Any ideas on how I'm screwing this up.

      Here are some snippets...

      @Name("bundleTree")
      @Stateful
      @Scope(ScopeType.SESSION)
      public class LicenseBundleTreeBean implements LicenseBundleTree {
      
       private static final long serialVersionUID = 7831424439727666930L;
      
       @PersistenceContext(unitName="LicenseServerPU")
       private EntityManager em;
      
       private Map<Object, TreeNode> licenseBundleNode;
      
       public void addChild(Object key, TreeNode value) {
       licenseBundleNode.put(key, value);
       setParent(this);
       }
      
       public TreeNode getChild(Object key) {
       return (TreeNode)licenseBundleNode.get(key);
       }
      
       public Iterator getChildren() {
       return licenseBundleNode.entrySet().iterator();
       }
      
       @Factory("licenseBundleTree")
       public Object getData() {
       List<LicenseBundle> licenseBundles = null;
       licenseBundleNode = new HashMap<Object, TreeNode>();
       licenseBundles = em.createQuery("from LicenseBundle b").getResultList();
       for (LicenseBundle bundle : licenseBundles) {
       Hibernate.initialize(bundle.getLicensePools());
       addChild(bundle.getId(), new LicenseBundleNode(bundle, this));
       }
       return this;
       }
      
       ....
       }
      
      public class LicenseBundleNode implements TreeNode {
      
       private static final long serialVersionUID = 6538893782173016812L;
      
       private LicenseBundle licenseBundle;
      
       private Map<Object, TreeNode> licensePool;
      
       private TreeNode parent;
      
       private LicenseBundleNode() {}
      
       public LicenseBundleNode(LicenseBundle bundle, LicenseBundleTree parent) {
       licenseBundle = bundle;
       this.parent = parent;
       }
      
       public void addChild(Object key, TreeNode value) {
       licensePool.put(key, value);
       }
      
       public TreeNode getChild(Object key) {
       return (TreeNode)licensePool.get(key);
       }
      
       public Iterator getChildren() {
       return licensePool.entrySet().iterator();
       }
      
       public Object getData() {
       List<LicensePool> pools = licenseBundle.getLicensePools();
      
       for (LicensePool pool : pools) {
       addChild(pool.getId(), new LicensePoolNode(pool, this));
       }
       return this;
       }
      
       .......
       }
      
      public class LicensePoolNode implements TreeNode {
      
       private static final long serialVersionUID = 3054960642034491845L;
      
       private LicensePool licensePool;
      
       private TreeNode parent;
      
       private LicensePoolNode() {}
      
       public LicensePoolNode(LicensePool licensePool, LicenseBundleNode parent) {
       this.licensePool = licensePool;
       this.parent = parent;
       }
      
       public void addChild(Object arg0, TreeNode arg1) {
       // TODO Auto-generated method stub
      
       }
      
       public TreeNode getChild(Object arg0) {
       // TODO Auto-generated method stub
       return null;
       }
      
       public Iterator getChildren() {
       // NOTE: This is a know work around for RichFaces Tree component
       return new ArrayList().iterator();
       }
      
       public Object getData() {
       return this;
       }
      
       public TreeNode getParent() {
       return parent;
       }
      
       public boolean isLeaf() {
       return true;
       }
      
      }
      
      web page...
      
       <rich:tree id="bundleTree" style="width:300px" value="#{bundleTree.data}"
       var="item" nodeFace="item.type">
       <rich:treeNode id="bundleTreeNode" type="LicenseBundleTree">
       <h:outputText value="#{item.type}" />
       </rich:treeNode>
       <rich:treeNode id="bundleNode" type="LicenseBundleNode">
       <h:outputText value="#{item.id}" />
       </rich:treeNode>
       <rich:treeNode id="poolNode" type="LicensePoolNode">
       <h:outputText value="#{item.id}" />
       </rich:treeNode>
       </rich:tree>