my dog learned polymorphism*
The moose likes Struts and the fly likes ArrayList in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ArrayList in Struts" Watch "ArrayList in Struts" New topic
Author

ArrayList in Struts

Anjali Krishnan
Greenhorn

Joined: May 02, 2006
Posts: 7
Can someone please let me know if the way I am accessing ArrayList is correct way or not

I am using an ArrayList to store a list of String where the number of input changes.
My code ActionForm :
List numberList = new ArrayList();
public List getnumberList() {
return numberList;
}

public void setnumberList(List newnumberList) {
numberList = newnumberList;

}
public String getnumber(int index) {
if (numberList == null){

numberList = new ArrayList();
}
while (numberList.size() <= index){
numberList.add(StringUtils.EMPTY);
}
return (String) numberList.get(index);
}
public void setnumber(int index, String number) {
if (numberList == null){

numberList = new ArrayList();
}
while (numberList.size() <= index){
numberList.add(StringUtils.EMPTY);
}
numberList.set(index, number);
}

First time I Initilaize the ArrayList to show 20 input fields

while (numberList.size() < 20){
numberList.add("");
}


JSP:
<logic:iterate id="number" indexId="numberCount"
name="reshipFreightSelectionForm"
property="numberList"
type="java.lang.String">
<td>
<html:text name="form"
property='<%="number[" + index + "]"%>'
size="11"
maxlength="11"/>

</td>
</logic:iterate>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ArrayList in Struts