Atta,

You can use indexed properties in your ActionForm class.  The key is having
all of the correct methods in your form class.

1)  Getter and setter:  You need a get/Set method for the collection that
you refer to in your jsp.  for example:
public Collection getLocations()
public void setLocations(Collection locs)

2) Getter and setter for one instance in the collection.  The name that you
use must match the name you define in your jsp as a single instance from
the collection (specified as the id).  For example:
    <logic:iterate name="locations" id="oneLocation"
            type="com.myco.toolkits.beans.Location">
        <td>
            <html:text name="oneLocation" property="locationName" indexed
="true"/>
        </td>
        <td>
            <html:text name="oneLocation" property="locationAddress"
indexed="true"/>
        </td>
    </logic:iterate>

Your form should in this case have the following get/set methods:
public com.myco.toolkits.beans.Location getOneLocation(int index)
public void setOneLocation(int index, com.myco.toolkits.beans.Location
oneLocation)

Your code may never use either of the "oneLocation" methods, but they are
important for Struts.  When your page is submitted, your two indexed
properties will be submitted as oneLocation[ix].locationName &
oneLocation[ix].locationAddress where ix is the index of the row (0-10 for
example).  As Struts proceses the indexed items, Struts will use the
"getOneLocation" method to get the Collection instance for the provided
index.  This method must resize the collection as needed and then return
the object for the provided index.  For example, if your collection has no
objects and the getter receives an index of 2, the method should load the
first three (0, 1, 2) collection locations with an initialized object and
return the third object.  Struts will then populate the appropriate
property in that object.

As an aside, I tend to use the ArrayList object as my collection type when
working with indexed properties, but I know that the Vector works equally
well.  A simple array will work fine, but the logic to expand the size is a
little more involved.

Let me know if this helps.
Nick



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

Reply via email to