wood burning stoves 2.0*
The moose likes Struts and the fly likes checkbox, arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "checkbox, arraylist" Watch "checkbox, arraylist" New topic
Author

checkbox, arraylist

azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
I have checkboxes in my form.


I want to iterate the selected values in another form.
So, since I require ArrayList, i am having the below code in ActionForm.


But the Arraylist is always empty.
Why is it so?
If the above code is wrong, how do i do it?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
First of all, when creating a group of checkboxes, it's better to use <html:multibox> rather than <html:checkbox>

Secondly, the expression:

Arrays.asList(permissions)

does not return an ArrayList. It returns an unspecified implementor of the List interface. See for yourself in the Java API Docs

If you want to do it this way, try this:

this.permissions = new ArrayList();
this.permissions.addAll(Arrays.asList(permissions));

Thirdly, if you're going to represent the values internally as a List and externally as a String[], that's fine, but both your getter and setter must treat it as a String[]. If you want to have a second getter and setter pair with a different name that treats it as a List, that's fine, but Struts expects the getter and setter for a property to be consistent in that they work with the same data type.
[ August 13, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: checkbox, arraylist