4 Replies Latest reply on Mar 25, 2008 5:27 PM by damatrix

    Binding data on elements in an ArrayList

    damatrix

      I have the need to populate the fields of entities contained in an ArrayList in a long running conversation as ff


       <ui:repeat value="#{specifications}" var="#{specification}">
            <h:panelGrid columns="2">                                            
               <s:decorate template="/layout/edit.xhtml">
                    <ui:define name="label">Label</ui:define>
                     <h:inputText value="#{specification.name}"/>                                                    
                </s:decorate>
                <s:decorate  template="/layout/edit.xhtml">
                     <ui:define name="label">Detail</ui:define>
                      <h:inputText value="#{specification.detail}"/>
                 </s:decorate>
             </h:panelGrid>
        </ui:repeat>
      



      The specifications is an outjected ArrayList containing about 4 individual specification entities that may or may not be specified.


      I find that data entered into the name and detail fields of the specification entities are not bound to those fields when the form is submitted.


      I'm trying to avoid the case of outjecting 4 different specification entities and populating them individually, since the user may decide that they want to have more than for specifications for a product.


      Any idea how the ui:repeat tag can still bind details specified in the fields of inputText components to the entity?

        • 1. Re: Binding data on elements in an ArrayList
          • 2. Re: Binding data on elements in an ArrayList
            damatrix

            I just tried it. It is able to display the set of name,specificatino fields just like the ui:repeat, but data entered into the inputText fields are not bound to the underlying entities contained in the ArrayList after the form is submitted.


            Am i missing something here? This is how the section of the facelet looks now



            <c:forEach items="#{specifications}" item="#{specification}">
                   <h:panelGrid columns="2">                                            
                       <s:decorate template="/layout/edit.xhtml">
                           <ui:define name="label">Label</ui:define>
                                 <h:inputText value="#{specification.name}"/>                                                    
                        </s:decorate>
                        <s:decorate  template="/layout/edit.xhtml">
                            <ui:define name="label">Detail</ui:define>
                               <h:inputText value="#{specification.detail}"/>
                         </s:decorate>
                     </h:panelGrid>
              </c:forEach>


            • 3. Re: Binding data on elements in an ArrayList
              mokua

              Try this:



              <c:forEach items="#{specifications}" var="specification">
                     <h:panelGrid columns="2">                                            
                         <s:decorate template="/layout/edit.xhtml">
                             <ui:define name="label">Label</ui:define>
                                   <h:inputText value="#{specification.name}"/>                                                    
                          </s:decorate>
                          <s:decorate  template="/layout/edit.xhtml">
                              <ui:define name="label">Detail</ui:define>
                                 <h:inputText value="#{specification.detail}"/>
                           </s:decorate>
                       </h:panelGrid>
                </c:forEach>


              • 4. Re: Binding data on elements in an ArrayList
                damatrix

                Thanks. I should not have put the word specification in EL quotes.
                This worked perfectly.