2 Replies Latest reply on Apr 23, 2007 11:50 AM by damianharvey

    inputText form array / dynamic form

    damianharvey

      Hi,

      I have a form based inside a rich:datatable. The number of fields is dynamic and is backed by an ArrayList in the Bean. I understood that I can use an Array, Set or Map and refer to it in the page by:

      <h:inputText id="firstname" value="#{myBean.name[0].firstname}"/>
      <h:inputText id="firstname" value="#{myBean.name[1].firstname}"/>
      etc.

      This works fine for the output of the value that was set in the Bean however it doesn't work in reverse - ie. if I change this value, the change is not reflected in the bean.

      I've tried to find an example of this, but none exists (maybe that's a hint that it won't work?)

      Is this possible or am I grasping? Should I just retrieve the input values in the Bean using the getParameters()?

      If the latter, how have people got around the fact that the parameter map doesn't have an array of 'firstname', but instead has something like 'myform:mydatatable:0:firstname' and myform:mydatatable:1:firstname'?

      Thanks,

      Damian.



        • 1. Re: inputText form array / dynamic form
          pbrewer_uk

          I'm not sure if I completely understand what you are trying to achieve, but why not use something like facelets <ui:repeat> or tomahawks <t:dataList> component?

          E.g.

           <ui:repeat value="#{myBean.name}" var="arrayItem">
           <h:inputText id="firstname" value="#{arrayItem.firstname}"/>
           </ui:repeat>
          


          Hope this helps, Pete.

          • 2. Re: inputText form array / dynamic form
            damianharvey

            Thanks. You are dead right.

            I (stupidly) had some code that was getting called by Ajax4JSF that was resetting everything.

            Using a rich:datatable works fine for inputting tables of data. I hadn't realised that the 'var' was not just for output but also for input.

            <rich:dataTable id="voyageDetails"
             var="row" value="#{myBean.listOfObjects}">
             <rich:column>
             <f:facet name="header">Name</f:facet>
             <h:inputText value="#{row.name}">
             </rich:column>
             ....
             etc