I have an ActionForm with the following collection of methods to operate on an array of type FormFile:
The problem occurs when I click submit on the interface side. Instead of using one of the set methods, the array is obtained via the getFiles method, as if the reflection api can't find either of the set methods.
I'm attempting to upload a variable number of multiple files, so the array size isn't known until the form is submitted, which results in an ArrayOutOfBoundsException when more than one file is attached, due to the previously mentioned oddity. (the files array initially has one element).
You've discovered one of the ugly dark corners of Struts. I've had this issue as well. It doesn't happen with checkboxes but with textfields - wooo doggies! I believe it would be worth posting to the user list, which can be found on the Struts official site. Since the people there wrote the code, they may be more intimate with how to get around it.
In the meantime, I will let you know my fix. I store a value in session that represents the largest number the index can be. Then in the reset method I initialize the array to the length of this max value. Don't forget to change the max value if you ever have list size greater than the current max value.
Part of the necessity for the max value is that a user can use browser back buttons to submit old data that might have too many indexed values - and Struts will garbage up before you ever get a chance in your Action to handle the fact that it is an invalid submission.
Best of luck!
A good workman is known by his tools.
Joined: Aug 08, 2003
I have a few 'dirty tricks' up my sleeve but I was hoping for a clean solution.