• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ArrayList in Struts

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic