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

Use ArrayList in ActionForm

Ranch Hand

Joined: Mar 11, 2003
Posts: 33

I used ArrayList in my ActionForm, but when I tried to access the ArrayList in JSP, I always get IndexOutOfBoundsException from ArrayList (which has size 0). If I change the ArrayList to type array, then everything works fine (I need to initialize the array in ActionForm to some fixed bigger size first). Under certain situation, I really want to use ArrayList to capture user input data, since I don't know how many the user is going to enter. Could someone help me on this problem? Thanks a lot in advance. What follows is my code:

[ June 08, 2006: Message edited by: JW Li ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This link should give you some ideas on what to do.

Consultant, Sima Solutions
Ranch Hand

Joined: Mar 11, 2003
Posts: 33

Thanks very much for your information! I tried most of the suggestions on that page, but still have problem I think I might have done something wrong, which is too subtle to be found... Sometimes the error is cannot find setXXX method when it's actually clearly defined in the ActionForm, and sometimes it's about getXXX not defined, (and I got confused by plural/single methods, like getter methods for items data member, we should have getItems() of course, and getItems(int index), or getItem(int index)..., when I have getItems() and getItems(int index), struts complains it cannot find getItems... I also tried LazyList, but got argument mismatch on the setter method after post the form(i.e. setItems())... Anyway, I feel highly frustrated by the way struts handle ActionForm. It has way too many black boxes (dependenency on common.beanutils implementation, from where I got most of the exception, and don't know what to do with them...) I really don't think it's worthy of a developer's time to try to resovle a simple post problem, which if doing old fashioned way, is much simplier and clearer... I feel I should start to think seriously about moving to other framework at all, though not clear what's better out there now. Anyway, for my original problem, I could just use Array and finish the work. I gave up using ArrayList in the ActionForm. Thanks again for your help. At least, now I know it's part of their bugs.
I agree. Here's the link:
subject: Use ArrayList in ActionForm
It's not a secret anymore!