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

    inputText form array / dynamic form

    Damian Harvey Master


      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}"/>

      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'?



        • 1. Re: inputText form array / dynamic form
          Peter Brewer Novice

          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?


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

          Hope this helps, Pete.

          • 2. Re: inputText form array / dynamic form
            Damian Harvey Master

            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}">
             <f:facet name="header">Name</f:facet>
             <h:inputText value="#{row.name}">