Struts does not necessairly create an ActionForm out of the returned data,
it uses the current one and repopulates it via the property names specified
in your <html:form>.  What you need are indexed properties, see archive.
You'll end up having something like:

throw all this in an iterate tag to iterate over all the rows in your form.
You'll need to declare an index variable in your jsp.

   <html:form action="/lookup">
     <table>
        <%
            int index = 0;
        %>

        <!-- iterate tag goes here -->
       <tr>
         <td><html:text property='<%= "person[" + index + "].first"
%>'/></td>
         <td><html:text property='<%= "person[" + index + "].last"
%>'/></td>
         <td><html:text property='<%= "person[" + index + "].phone"
%>'/></td>
       </tr>

        <%
            ++index;
        %>

     </table>
   </html:form>


----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 03, 2001 8:21 AM
Subject: variable number of inputs


> Newbie question...
>
> I need to have a table where each row will have multiple input fields
> and these fields make up a single record of information. I do not
> know before I generate the table how many rows it will have. When the
> user modifies this table and sends it back, struts will want to make
> an ActionForm out of the returned data. The question is, how do I
> handle the variable number of rows?
>
> For example, if each row has a first name, last name, and phone number,
> and I happen to have two rows, I might do something like:
>
>   <html:form action="/lookup">
>     <table>
>       <tr>
>         <td><html:text property="first"/></td>
>         <td><html:text property="last"/></td>
>         <td><html:text property="phone"/></td>
>       </tr>
>       <tr>
>         <td><html:text property="first"/></td>
>         <td><html:text property="last"/></td>
>         <td><html:text property="phone"/></td>
>       </tr>
>     </table>
>   </html:form>
>
> (Of course, since the number of rows is variable, I'd actually do that
> in an iterator, but humor me).
>
> So when the setter methods are called in the ActionForm, the setter for
> each of the fields will get called multiple times. If I can trust the
> order in which they're called, I can regroup them as records later. But
> I don't know if that's kosher.
>
> Another option would be to modify the property names to contain a
> unique number such as:
>
>   <html:text property="first2"/>
>
> But then, of course, I can't statically compile the setter methods for
> each case into the ActionForm. And there doesn't appear to be a method
> in ActionForm that's called for unrecognized properties.
>
> This must be a common problem. How is it usually handled?
>
> Devon

Reply via email to