This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
In a request scoped bean, everything in it goes away after the page is displayed, including the array list. For a regular text field, this is OK, because when the user submits the form, Struts creates a new instance of the form bean and populates the property with what the user entered on the form. However, an ArrayList that you put in the form bean before the page was displayed does not get rebuilt automatically. The newly instantiated ActionForm bean has, at best, an empty one.
You have 2 choices:
1-Change the scope of the ActionForm to session. 2-Override the reset(...) method of ActionForm and in it add logic to rebuild your array list from the database or whatever source it comes from.
Make sure that you have used indexed properties on your JSP, and that you have indexed getters and setters in your form bean.
See this link for more information on indexed properties.
This is how I code the get method for my indexed properties. You don't need the null check if you initialize your list in the constructor or where the variable is declared. You will find that the indexes get submitted in what seem like random order (10, 3, 5, ...). That is why the second block of code is a loop.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com