How struts2 store forms elements in Array on the Action ? (Prior Java5)

If you have an array of Integer[] weights and String[] names on the actions class then 
here is an example to store data on those arrays in action class.

For example consider below form with the textfields of 'weights' and names[index]

=============

<s:form action="MyArraysAction">
<s:textfield name="weights" label="Weight"/>
<s:textfield name="weights" label="Weight"/>
<s:textfield name="weights" label="Weight"/>

<s:textfield name="names[0]" label="names"/>
<s:textfield name="names[1]" label="names"/>
<s:textfield name="names[2]" label="names"/>
<s:submit/>
</s:form>

=============

private Integer[] weights ;
public Double[] getWeight() {
return weights;
}
public void setWeight(Double[] weights) {
this.weights = weights;
}

private String[] names = new String[10];
public String[] getNames() {
return names;
}
public void setNames(String[] names) {
this.names = names;
}

=============

When you submit above form with proper data, struts OGNL expression will find the weights property on the action class object. As there are multiple parameter with same name in request it will be submitted as array.
Here the weights property is an array of element type Integer. OGNL sees this and automatically runs its type conversion for each element of the array.
The array of weights is initialized by the framework fo us, so we do not need to initialized it.

For names[index] textfields the servlet API will consider each element as a separate paremeter, so all will be submitted individually but However, when the framework hands these names to OGNL , they’re accurately interpreted as references to specific elements in a specific array. These parameters are set, one at a time, into the elements of the names array. In this second type array submission we need to initialize the Array on the action because we are specifying the inidividual index for each name element and OGNL has to set each element at specified index into the Array on Action.

=============

Using below code snippet you can display the array values on the View Jsp page.

<h3>Weight for element 1 = <s:property value="weights[1]" /> </h3>
<h3>Name for element   1 = <s:property value="names[1]" /> </h3>