Here is how I've successfully handled input arrays.

My HTML form input accepts up to 12 monthly date/value pairs:

  <table border="0" cellspacing="2">
    <tr class="titleBlock" valign="bottom">
      <th></th>
      <th>Date Rated</th>
      <th>Unit Capacity</th>
    </tr>
  <c:forEach var="i" begin="0" end="11" varStatus="row" >
    <tr>
      <td align="right"><font class="fieldDisplay"><c:out
value="${row.count}"/></font>&nbsp;</td>
      <td align="center" class="fieldInput"><html-el:text
property="dateRated[${row.index}]" size="10" maxlength="10"/></td>
      <td align="right" class="fieldInput"><html-el:text
property="capacity[${i}]" size="10" maxlength="10"/></td>
    </tr>
  </c:forEach>
  </table>

Then in the form bean associated with the action, you need indexed
getters/setters like:

    public void setDateRated(int idx, String value)
    {
        //Log.log(this+".setDateRated("+idx+", "+value+")");
        if(StringTools.isStringNull(value))
            gDateRated[idx] = value;
        else
            gDateRated[idx] = DateTools.zeroFillDate(value);
    }
    
    public String getDateRated(int idx)
    {
        //Log.log(this+".getDateRated("+idx+")
returning:["+gDateRated[idx]+"]");
        return(gDateRated[idx]);
    }
    
    public String getCapacity(int idx)
    {
        //Log.log(this+".getCapacity("+idx+")
returning:["+gCapacity[idx]+"]");
        return(gCapacity[idx]);
    }
    
    public void setCapacity(int idx, String value)
    {
        //Log.log(this+".setCapacity("+idx+", "+value+")");
        gCapacity[idx] = value;
    }

Hope this helps.

- Frank.

-----Original Message-----
From: Samuel Rochas [mailto:[EMAIL PROTECTED] 
Sent: Thursday, May 06, 2004 10:10 AM
To: Struts Users Mailing List
Subject: Handle dynamic form (form/iterate)


Hello,

My app has a form which content is generated dynamicly with the help of 
an iterate tag.

The form displayed is fine, the fields in the repeated lines have all 
the same name, which is correct and easy to handle with servlet.

How can I handle this fields in my xForm / xAction classes? How do I 
have to declare the attributes? How do I have access to them?

Sincerly
Samuel

---  andinasoft SA - Software y Consulting  ---
Mariano Aguilera 276 y Almagro - Quito, Ecuador
Tel. +593 2 290 55 18 ---- Cel. +593 9 946 4046
---------  http://www.andinasoft.com  ---------

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to