1 Reply Latest reply on Apr 30, 2008 5:35 PM by grundor

    How to use rich:treeNodesAdaptor programmatically?

      Hello,

      I am trying to programmatically create a rich:tree from a model stored in the database. The tree is nested within a rich:panelMenuGroup. The panelMenu itself is dynamically created.

      Here is the snippet of xhtml page source that shows the panelMenu binding:

       <h:form id="navform">
       <rich:panelMenu id="navMenu" binding="#{navigationAction.navMenu}">
       </h:form>
      


      Here is the getNavMenu implementation and code where the tree creation is attempted in my Seam component:
       public HtmlPanelMenu getNavMenu() {
      
       if (navMenu != null)
       return navMenu;
      
       return buildNavMenu();
       }
      
       private HtmlPanelMenu buildNavMenu() {
       List<Menutab> menutabs = sportHome.getInstance().getMenutabs();
       navMenu = new HtmlPanelMenu();
       navMenu.setExpandSingle(true);
      
       for (Menutab tab : menutabs) {
       HtmlPanelMenuGroup group = new HtmlPanelMenuGroup();
       String label = tab.getMenutabCaption();
       group.setLabel(label);
      
       String name = "navgrp_" + tab.getMenutabId();
       group.setName(name);
      
       // Add pre-defined items
       if (tab.getMenutabType() == MenutabType.MENUTAB_TEAMS) {
       addTeamTree(group, tab.getSport().getSeasons());
       }
      
       navMenu.getChildren().add(group);
       }
      
       return navMenu;
       }
      
       private void addTeamTree(HtmlPanelMenuGroup parentGroup, List<Season> seasons) {
       HtmlTree teamTree = new HtmlTree();
       teamTree.setSwitchType("client");
      
       HtmlTreeNodesAdaptor seasonAdaptor = new HtmlTreeNodesAdaptor();
       seasonAdaptor.setNodes(seasons);
       seasonAdaptor.setVar("_season");
      
       HtmlTreeNode seasonNode = new HtmlTreeNode();
       seasonNode.setData("#{_season.seasonId}");
       seasonNode.setIcon("img/season.png");
       seasonNode.setIconLeaf("img/season.png");
      
       HtmlOutputText text = new HtmlOutputText();
       text.setValue("#{_season.seasonName}");
      
       seasonNode.getChildren().add(text);
       teamTree.getChildren().add(seasonNode);
       parentGroup.getChildren().add(teamTree);
       }
      


      So basically I am dynamically creating a MenuPanel control, and within one of the MenuPanelGroups I am attempting to create a tree control using HtmlTreeNodesAdaptor.

      The panelmenu is displaying just fine, but the tree control does not display using the above code. Can anyone comment on whether I am on the right track? Is it valid to use HtmlTreeNodesAdaptor in this way?

      Regards,
      Mark


        • 1. Re: How to use rich:treeNodesAdaptor programmatically?

          Another option I can see is to simply embed an a4j:include within the PanelMenuGroup. My included xhtml would then use the rich:treeNodesAdaptor and recursive versions to create the tree.

          It seems to work fine when I statically code the include into the PanelMenu, but when I try it in code it never shows up:

           HtmlPanelMenuGroup group = new HtmlPanelMenuGroup();
           String label = tab.getMenutabCaption();
           group.setLabel(label);
          
           String name = "navgrp_" + tab.getMenutabId();
           group.setName(name);
          
           Include myInclude = new Include();
           myInclude.setViewId("/layout/navtree.xhtml");
           group.getChildren().add(myInclude);
          


          Unfortunately I can't code it statically as I need to allow the user to reogranize the order of the panelmenugroups.

          -Mark