1 Reply Latest reply on Jul 25, 2007 9:54 PM by Maria Consuelo Franky

    Can drop down menus be created programmatically?

    Robert Linn Newbie

      I would like to read menu options programmatically from a database and render them using the Richfaces Html Menus.
      I'm able to read in the menu options, load them into new HtmlDropDownMenu objects along with any sub-option children HtmlMenuItems and return the List.
      How would I render such a List in the JSF page using <ui:repeat> ?
      When I use

      JSF Code:
      <ui:repeat value="#{menuBean.dropDownMenus}" var="ddMenu">
       <rich:dropDownMenu value="#{ddMenu.value}"/>
      </ui:repeat>
      


      Java managed bean:
      public List<HtmlDropDownMenu> getDropDownMenus() {
       List<HtmlDropDownMenu>menus = new ArrayList();
       (load menus from database)
       HtmlDropDownMenu menu = null;
       Iterator iter = menus.iterator();
       while (iter.hasNext()) {
       menu = iter.next();
       (Determine if sub-options exist and if so add them)
       HtmlMenuItem menuItem = new HtmlMenuItem();
       String subOption = "subOption";
       menuItem.setValue(subOption);
       menu.getChildren().add(menuItem);
       menus.add(menu)
       }
       return menus;
      }
      

      I can see the HtmlDropDownMenu values but the children HtmlMenuItems do not appear.

      When I return a single HtmlDropDownMenu from the managed bean like this:
      <rich:dropDownMenu binding="#{menuBean.testDropDownMenu}">
      </rich:dropDownMenu>
      

       public HtmlDropDownMenu getTestDropDownMenu() {
       HtmlDropDownMenu menu = new HtmlDropDownMenu();
       menu.setStyle("border:1px solid #BCD1FF");
       menu.setDirection("bottom-right");
       menu.setJointPoint("tr");
       menu.setValue("Home: Manual");
       HtmlMenuItem menuItem = new HtmlMenuItem();
       String subOption = "subOption";
       menuItem.setValue(subOption);
       menu.getChildren().add(menuItem);
       return menu;
       }
      

      , it works correctly; i.e. the children options get rendered.
      Whether I use binding or value in the <ui:repeat> does not render the sub-options.

      Any thoughts are greatly appreciated.
      Thanks

        • 1. Re: Can drop down menus be created programmatically?
          Maria Consuelo Franky Newbie

          Hello:

          After following your indications I have found a solution for building dynamically a list of menus with RichFaces elements:

          In the screen:

          <h:form id="menuRich">
           <rich:toolBar binding="#{toolBar}">
           </rich:toolBar>
          </h:form>


          Where toolBar variable is built in Java as follows:

          HtmlToolBar toolBar;
          ...
          List<HtmlDropDownMenu> theMenu = getMenuRich();
          
          toolBar = new HtmlToolBar();
          toolBar.setItemSeparator("disc");
          for (HtmlDropDownMenu mainMenu : theMenu) {
           toolBar.getChildren().add(mainMenu);
          }