This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
The problem is with this statement in your ActionForm:
Since you never initialize the String array, you can never set any of its elements because it doesn't have any.
The quick and dirty way to get around this would be to initialize the array with the size being some arbitrary value you don't expect to be exceeded, and just deal with the fact that some elements in the array will be null and hope the actual size never exceeds the value you set.
Two better solutions would be:
Carry forward the array size as a hidden field in the JSP and then override the reset(...) method of the Action form and have it retrieve the value from the request and initialize the array to that size
Use a List instead of an array and use "lazy initialization" techniques in your indexed getter and setter to add elements to the List if they're not already there.
[ July 11, 2008: Message edited by: Merrill Higginson ]
I haven't got the chance to try your solution yet. One more question though... So even though I came from an action, initialized the array there before entering the JSP, I still won't be able to get the values?
Joined: Feb 15, 2005
Assuming your ActionForm is in request scope, The instance of the ActionForm that is created when the form is submitted is a different instance than was used at the time the JSP was rendered, which is now out of scope. That's why you have to initialize the array in the ActionForm.