Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList in Struts

 
Anjali Krishnan
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic