• 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

Indexed field

 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dang!

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

Thank you very much for the info!
 
reply
    Bookmark Topic Watch Topic
  • New Topic