5 Replies Latest reply on Apr 30, 2009 10:03 AM by Nick Belaevski

    Create the rich:dropDownMenu items dynamicly

    Maxim Kuzmik Newbie

      Hello.

      How can i create the menu item (rich:menuItem) dynamicly? Or where can i see the examples?

      Thanks.

        • 1. Re: Create the rich:dropDownMenu items dynamicly
          Nick Belaevski Master

          Hello,

          Either use:

          1. c:forEach tag

          or:

          2. Bind menu/group to some bean property, then call application.createComponent(UIMenuItem.COMPONENT_TYPE) to create menu items

          • 2. Re: Create the rich:dropDownMenu items dynamicly
            Maxim Kuzmik Newbie

             

            "nbelaevski" wrote:
            Hello,
            2. Bind menu/group to some bean property, then call application.createComponent(UIMenuItem.COMPONENT_TYPE) to create menu items


            Can you give the examples? I don't underatand about "application.createComponent(UIMenuItem.COMPONENT_TYPE)". About create the bean all is ok - I just create java class take the @ on it. and than I can use it in my pages. In this class I will create menu rich:rich:dropDownMenu and all others nessasary components. But How after that I can put in inside rich:toolBar the on my pages?

            So How can i Create dynamicly the next code and insert it into the tag rich:toolBar?
             <rich:dropDownMenu>
             <f:facet name="label">
             <h:panelGroup>
             <h:outputText value="File"/>
             </h:panelGroup>
             </f:facet>
             <rich:menuItem submitMode="ajax" value="#{messages['label.logout']}" action="#{identity.logout}" />
             </rich:dropDownMenu>
            
             <rich:dropDownMenu>
            
             <f:facet name="label">
             <h:panelGrid cellpadding="0" cellspacing="0" columns="2" style="vertical-align:middle">
             <h:outputText value="Help" />
             </h:panelGrid>
             </f:facet>
            
             <rich:menuItem submitMode="ajax" value="About..." action="" />
             </rich:dropDownMenu>
            
            


            • 3. Re: Create the rich:dropDownMenu items dynamicly
              Nick Belaevski Master

              1.

              <rich:toolBar binding="{bean.toolbar}" />


              "bean" should not be application, session or conversation-scoped. "bean.toolbar" is of type javax.faces.component.UIComponent

              2. In the bean do the following:
              if (toolbar.getChildCount() == 0) {
               UIDropDownMenu menu = (UIDropDownMenu) application.createComponent(UIDropDownMenu.COMPONENT_TYPE);
              
               //fill in attributes - read more about UIComponent/ValueExpression/MethodExpression types in JSF spec./Javadocs
               ..
               //create rest of components
              
               toolbar.getChildren().add(item);
              }





              • 4. Re: Create the rich:dropDownMenu items dynamicly
                Maxim Kuzmik Newbie

                What method must be in my bean? i don't undertand =( Sorry, but i'm beginner in RichFaces.

                • 5. Re: Create the rich:dropDownMenu items dynamicly
                  Nick Belaevski Master

                   

                  public UIToolBar getToolbar() {
                   if (toolbar == null) {
                   toolbar = (UIToolBar) application.createComponent(UIToolBar.COMPONENT_TYPE);
                   UIDropDownMenu menu = (UIDropDownMenu) application.createComponent(UIDropDownMenu.COMPONENT_TYPE);
                  
                   //fill in attributes - read more about UIComponent/ValueExpression/MethodExpression types in JSF spec./Javadocs
                   ..
                   //create rest of components
                  
                   toolbar.getChildren().add(item);
                   }
                  
                  }