File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Indexed field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Indexed field" Watch "Indexed field" New topic

Indexed field

Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
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).

Any help will be appreciated
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

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.
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326

I have a few 'dirty tricks' up my sleeve but I was hoping for a clean solution.

Thank you very much for the info!
I agree. Here's the link:
subject: Indexed field
It's not a secret anymore!