I had this problem, and worked out a solution that seemed workable.
The main thing to remember with the <html:xxx/> tags is the
the name part should always be the name of the form bean, and
the property be relative to that, otherwise the BeanUtils won't
be able to repopulate the form.

I tend to store my collections in SortedMap's and use the
primary key of the database table as the index into the
SortedMap (This means, each bean has a getId() which is an integer,
and the Bean has the comparable interface to sort them). Then when
I do the iterate, I iterate over the keys of the map and return just
the Map.Entry values. Then when I do the <html:xxx/> I have
something like (this if from memory, based on your code, it might
take a few hacks to get right, I think you'll need a useBean for
the retailerForm, can remember)

        <logic:iterate id="entry" collection="<%= 
retailerForm.getRetailers().getEntries().iterator() %>">

                <html:text name="retailerForm" property="<%= retailerBean[\" + 
((Map.Entry) entry).getKey()) + \"]" %>"/>

                <%!-- or, if the bean identity id id, and so we use getId)( --%>

                <html:text name="retailerForm" property="<%= retailerBean[\" + 
((RetailerBean) ((Map.Entry) entry).getValue())).getId() + \"]" %>"/>

        </logic:iterate>

I use this method all the time, it works great.

Here's another message with a copy of the code I use

        http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg07627.html

> - I have a number of beans held in a Vector.
> - In my ActionForm I have a two getters for this vector - one returns the
> vector and one returns elements of the vector - so something like this:
> 
>     public RetailerBean getRetailerBean( int index )
>     {
>         return (RetailerBean)retailers.elementAt( index );
>     }
> 
> and
> 
>     public Vector getRetailers()
>     {
>         return retailers;
>     }
> 
> This works fine to populate using the following type of iterate tag:
> 
> <logic:iterate id="retailer" name="retailerForm" property="retailers">
>         <tr>
>         <td><html:checkbox name="retailer" property="delete"/></td>
>         <td><html:text name="retailer" property="name"/></td>
> </a></td>-->
>         </tr>
> </logic:iterate>
> 
> However, it doesn't repopulate the beans when I do a submit.  This is
> because the generated html is something like:
> 
> <input type="checkbox" name="delete">
> 
> rather than:
> 
> <input type="checkbox" name="retailer[0].delete">
> <input type="checkbox" name="retailer[1].delete">
> 
> which would allow my beans to be repopulated.
> 
> The outcome of this is that I have to create arrays for all properties of my
> beans in my ActionForm and take the values from there.  This seems like
> bodge-heaven and not at all object-oriented.
> 
> If the form can be populated directly from the beans then surely it should
> work the other way too.

Reply via email to