Two tips that I have learned that seem to cause problems are:
Use a different name for your indexed get method
In my example I had a list of "order" items. For the get method that returns a List I chose the name getOrderList. For my indexed get method I chose the name getOrderItem. Some example use a name like "getOrders" for both methods, but this causes problems with some versions of Struts/BeanUtils, plus it seems more confusing to me. I also see examples that use names like getOrders and getOrder but to me the difference is subtle enough to cause confusion.
Note that the method setOrderList is never called by
Struts. It is only called from DisplayOrderIndexedAction.
Make sure the id attribute of your iterate tag matches the property name of your indexed get method
Note that the id attribute of my iterate tag is "orderItem" and my indexed get method is named "getOrderItem". If they do not match, then your page will display fine but your form will not be populated when the page is submitted.
It took me a while to figure this one out. For the first two years after I found out about indexed properties I did not use the indexed="true" attribute. Instead I used JavaScript to create the index like in the "Dynamic Indexes for Indexed Properties" section of the Struts document.
Note that my example completely avoided the topic of validation. I have always implemented validation for indexed properties by implementing a validate method in the form (plus I never use client side validation). My understanding is that the validator framework does not support indexed properties.
I also did not do any translation between "business/data objects" and "presentation objects". Struts wants
String properties for editable fields. Note that the quantity property in OrderItem is a String. In reality your business layer would return an object where quantity was an int or Integer (or long/Long) and the code would have to do some translation. This translation would occur in reverse when the quantity was updated.
For completeness, here is my dummy/mock business layer object:
- Brent
[ November 22, 2006: Message edited by: Merrill Higginson ]