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