3 Replies Latest reply on Jul 6, 2007 4:22 AM by Melanie Ntolo

    Richfaces Tree and Dinamic Gereration

    paata lominadze Master

      hi all,
      i tried to generate tree component dynamically i use richfaces tree example and add this to my PanelBar component :

      .........................
       HtmlPanelBarItem item= new HtmlPanelBarItem();
       item.setLabel("Blaaaa");
      
       Library library = new Library();
       HtmlTree tree = new HtmlTree();
       tree.setStyle("width:150px");
       tree.setValue(library.getData());
       tree.setVar("item");
       tree.setNodeFace(library.getType());
      
       Iterator<Artist> itArtists = library.getArtists().values().iterator();
       while (itArtists.hasNext()) {
       Artist artist = (Artist)itArtists.next();
      
       HtmlTreeNode artistNode = new HtmlTreeNode();
       artistNode.setType("artist");
       HtmlOutputText artistText = new HtmlOutputText();
       artistText.setValue(artist.getName());
      
       Iterator<Album> itAlbums = artist.getAlbums();
       while (itAlbums.hasNext()) {
       Album album = (Album) itAlbums.next();
      
       HtmlTreeNode albumNode = new HtmlTreeNode();
       albumNode.setType("album");
       HtmlOutputText albumText = new HtmlOutputText();
       albumText.setValue(album.getTitle());
       Iterator<Song> itSongs = album.getSongs();
       while (itSongs.hasNext()) {
       Song song = (Song) itSongs.next();
      
       HtmlTreeNode songNode = new HtmlTreeNode();
       songNode.setType("song");
       HtmlOutputText songText = new HtmlOutputText();
       songText.setValue(song.getTitle());
       tree.getChildren().add(songNode);
       }
       tree.getChildren().add(albumNode);
       tree.getChildren().add(artistNode);
       item.getChildren().add(tree);
       bar.getChildren().add(item);
      


      but i have two problem.
      first: tree does not working, it is not expandable (ajax request happened i see it on firebug - firefox extension)
      second - tree looks like :
      com.liliko.billing.businesslayer.beans.common.Artist@184a8e6
      com.liliko.billing.businesslayer.beans.common.Artist@620af1
      com.liliko.billing.businesslayer.beans.common.Artist@14be76b
      com.liliko.billing.businesslayer.beans.common.Artist@e5449e



      can anybody tried to use dynamic tree component ??


      Regards,
      Paata.

        • 2. Re: Richfaces Tree and Dinamic Gereration
          Melanie Ntolo Newbie

           

          tree looks like :
          com.liliko.billing.businesslayer.beans.common.Artist@184a8e6
          com.liliko.billing.businesslayer.beans.common.Artist@620af1
          com.liliko.billing.businesslayer.beans.common.Artist@14be76b
          com.liliko.billing.businesslayer.beans.common.Artist@e5449e
          


          If you have a static tree, you will define the treenodes something like this:
          <rich:treeNode id="adminOtauNode" name="adminOtauNode" value="item" type="OTAU">
          <h:outputText value="#{item.resource.name}" />
           </rich:treeNode>


          • 3. Re: Richfaces Tree and Dinamic Gereration
            Melanie Ntolo Newbie

            Psst: Sorry i submitted an uncomplete post just before...

            The way to put <h:outputText value="#{item.resource.name}" /> inside the <rich:treeNode></rich:treeNode> defines how the node will be displayed

            In your code, i could see HtmlOutputText artistText = new HtmlOutputText();
            But i didn't see the connection beewen your artistNode and this HtmlOutputText. So the HtmlOutputText doesn't relate to the node. That's why your tree displays the toString() of your node object

            HtmlTreeNode artistNode = new HtmlTreeNode();
             artistNode.setType("artist");
             HtmlOutputText artistText = new HtmlOutputText();
             artistText.setValue(artist.getName());