2 Replies Latest reply on Feb 27, 2009 9:04 AM by Mantshadi Mokoena

    help with selectOneMenu and for loop

    Mantshadi Mokoena Newbie

      Hi,


      I am new at Seam and JSF, I have a question regarding how I can dynamically create selectOneMenus with a for loop.


      in my backing bean of my project I have a for loop that compares two lists and creates a new list that it gets from a query to the database.


      my question is how do I create a selectOneMenu for each new list that is created.

        • 1. Re: help with selectOneMenu and for loop
          Binesh Gummadi Novice

                                           <h:selectOneMenu value="#{myclass.property}" partialSubmit="true" required="true">
                                 <s:selectItems value="#{myclass.newList}" 
                                                var="_item" 
                                                label="#{_item.name}" 
                                                noSelectionLabel="#{messages['please.select']}"/>
                                 <s:convertEntity />
                              </h:selectOneMenu>



          This should work unless I am missing something. If you don't want to use s:convertEnttiy then you can also use c:foreach



                                          <h:selectOneMenu id="orgDropdownId" value="#{myclass.property}" partialSubmit="true" required="true">
                                   <c:forEach items="#{myclass.newList}" var="_item">
                                        <f:selectItem itemValue="#{_item.id}" itemLabel="#{_item.name}" />
                                   </c:forEach>
                              </h:selectOneMenu>


          • 2. Re: help with selectOneMenu and for loop
            Mantshadi Mokoena Newbie

            Hi Binesh,


            Thank you so much for your reply. I tried both of them and I still only get one selectOneMenu box, what I need is a new selectOneMenu box for every new list created.


            Here is the code I have in my backing bean:


            public List<ParameterValue> getParamOrdervalueList(){
                      
                      paramOrdervalueList = new ArrayList<ParameterValue>();            
                        for (Parameter param:selectedParamList){
                             for(Parameter orderparam:orderList){
                                 String ordername = orderparam.getName().replace"_ORDER", "");
                                 if(param.getName().equals(ordername)){
                                     long id = orderparam.getId();
                                     paramOrdervalueList = em.createQuery("select value from ParameterValue where parameterId=:id").setParameter("id", id).getResultList();
                                                    
                                 }
                             }
                        }
                      return paramOrdervalueList;
                   }
            


            I think it has something to do with the JSF lifecycle, how do I render a new selectOneMenu everytime a new paramOrderList is returned by my method?