It looks like the problem is deep within BeanUtils.populate(..) method which
is what is called ultimately for mapping request parameters to bean properties.
The BeanUtils.populate(..) method is called in the processPopulate() method
of the RequestProcessor class (See
Struts src) and well before the execute(..) method of the action is called. This populate method is what calls your indexed getter/setter on your form.
Yes, the order of the parameters submitted is random, and this random order
throws off BeanUtils.populate(..). To illustrate..
<pre>
public class BeanUtilTest extends TestCase {
private int INPUT_NUM = 10;
public void testPopulateMethod() {
HashMap p = new HashMap();
for (int i = 0; i < INPUT_NUM; ++i) {
String key = "item[" + i + "].test";
String[] val = new String[] { String.valueOf(i) };
p.put(key, val);
}
System.out.println(p);
Bean bean = new Bean();
try {
BeanUtils.populate(bean, p);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(bean);
}
}
public class Bean {
private ArrayList items = new ArrayList();
public ArrayList getItems() {
return items;
}
public void setItems(ArrayList items) {
this.items = items;
}
public Item getItem(int index) {
if (index >= items.size()) {
Object o = new Item();
items.add(o);
return (Item)o;
}
return (Item) items.get(index);
}
public void setItem(int index, Object o) {
items.add(o);
}
public String toString() {
return items.toString();
}
public class Item {
private String
test;
public Object getTest() {
return test;
}
public void setTest(Object test) {
this.test = (String)test;
}
public String toString() { return test; }
}
</pre>
When you run this the result is..[0, 1, 2, 7, 4, 5].
When you convert HashMap p = new HashMap() to
LinkedHashMap p = new LinkedHashMap() to
the result is..[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] (as you would expect).
The thing is the Apache code uses java.util.HashMap for storing the request parameters.
At this point.. the behaviour of BeanUtils.populate(..) is erratic. I don't
see how modifying the indexed getter/setters in your form is going to make
any difference.
List based indexed properties in Struts are broken period.!