Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checkbox, arraylist

 
azhar bharat
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic