4 Replies Latest reply on Dec 6, 2011 9:23 PM by lobo369

    Dynamic DropDownMenu

    lobo369 Newbie

      I read a lot about this problem but I haven't could find any solutions that work for me.


      I want to create a dynamic dropdown by DB.


      I'm using Richfaces 3.3.2 SR1, Facelets 1.1, JSF 1.2


      I understand that Richfaces have problem to create a dynamic DropDownMenu by a4j:repeat or ui:repeat and the suggestion in internet is use c:foreach, but don't work for me.


      My page.xhtml is




      rich:toolBarGroup itemSeparator="line">
      <c:forEach var="itemmenu" items="#{reportes.barra.menus}"> 
      <rich:dropDownMenu value="#{itemmenu.text}" />                       //Don't be printed but let space and the separators are printed
      <h:outputText value="Menu4" />                                               //Printed OK
      <h:outputText value="#{reportes.barra.menus[1].text}" />           //Printed OK as only text
      <rich:dropDownMenu value="#{reportes.barra.menus[0].text}" /> //Printed OK as dropdown menu




      then my variables have good values, but c:foreach isn't working.


      I tryed to resolve my problem creating the dropdownmenus programatically but get the same result.




      In the tree you can see that c:foreach statment only create one dropdownmenu when the iterate variable "reportes.barra.menus" have three elements.


      And the same results with menuItem level.


      Any suggestion ? What's wrong ?


      Thank's in advanced.

        • 1. Re: Dynamic DropDownMenu
          Paul Dijou Newbie

          Shouldn't you use the "label" attribute instead of the "value" attribute in a dropDownMenu ? (or at least a "label" facet) Also, you can try to add some menuItem in each dropDownMenu just to be sure.

          • 2. Re: Dynamic DropDownMenu
            lobo369 Newbie

            Thank's Paul for your suggestion, but It isn't work to me. I don't understand why. I tried use a laber property and label facet with the same results.


            Originally I only wanted to put dynamic ItemMenu but I with the same behavor, then I decided to build all the dropdownmenu dynamically.


            I tried to binding a HtmlDropDownMenu but no way.  The component never been rendered.


            Any other suggestion ?

            • 3. Re: Dynamic DropDownMenu
              Paul Dijou Newbie

              First, my bad, there is not "label" attribute for dropDownMenu in RichFaces 3.x, this is a 4.x feature. So you were totally correct with your "value" attribute. Really sorry.


              I will just insist a bit. When I take a look at that demo, it seems that the toolbar has no problem with a c:forEach inside of it. In addition, in your screenshot, there is a few line separators even before the "Menu 4" label indicating that, maybe, it's trying to add something but quite empty. You can try a few steps :


              1) Replace your dropDownMenu with a "<h:outputText value="Test"/>" and see if the iteration is correct and the labels printed (as many as reportes.barra.menus.size()).


              2) Replace the outputText with : "<h:outputText value="#{itemmenu.text}"/>". This will check if the "getText()" method is correctly define in the "itemmenu" var.


              3) If it's fine, try to replace this outputText with :


                        <f:facet name="label"> 
                                  <h:outputText value="File"/>
                        <rich:menuItem value="New" action="test" />
                        <rich:menuItem value="Open" action="test"/>


              And see if it creates you several dropDownMenu (as many as reportes.barra.menus.size()), all the same of course.


              4) If it still works, you can replace the "File" value on the h:outputText in the "label" facet with your #{itemmenu.text}.


              5) Down know if you will arrive to this step, but if you do, then remove the two "rich:menuItem". Still working ?


              Hope this could help to better understand your problem.


              Just for information, here is how the RichFaces 4.x showcase menu is dynamicly build : http://anonsvn.jboss.org/repos/richfaces/trunk/examples/richfaces-showcase/src/main/webapp/templates/includes/navigation.xhtml

              Not exactly the same as your, but maybe it could help...

              1 of 1 people found this helpful
              • 4. Re: Dynamic DropDownMenu
                lobo369 Newbie

                Thanks a lot Paul.


                I followed your steps and identified the problem.


                The <c:foreach> didn't work to me because I was traing use JSTL for jsp with facelets.


                I changed the taglib and all came to work fine :-)


                The correct taglib to use with facelets is xmlns:c="http://java.sun.com/jstl/core" insted of xmlns:c="http://java.sun.com/jsp/jstl/core"