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

Struts2: preselect checkbox

Bhaarat Sharma
Ranch Hand

Joined: Jun 04, 2007
Posts: 96
I have a checkbox in a form. There are multiple checkboxes on this form and when the form is submitted these checkboxes are validated (not using annotations).

if not all checkboxes are checked then control is coming back to the same page with an error message. But even the checked checkboxes are unchecked when control comes back to this page because of error.

according to the struts2 ui documentation the value="" attribute should be used if something needs to be preselected but its not working for me.

in my action class I have getters and setter for privacy and formcheckBox

I'd appreciate any help.

Also struts2 is automatically making hidden tags like this

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The checkbox tag will automatically take its value from the value of the property in the Action class. Just omit the value attribute entirely from the tag, and it should work fine.

Consultant, Sima Solutions
Bhaarat Sharma
Ranch Hand

Joined: Jun 04, 2007
Posts: 96
I tried that and it is only working when my fieldValue="true" if i replace it with something else, say, fieldValud="something" it doesnt work

modified example

getters setters

are we not allowed to have anything else in fieldValue?
[ December 12, 2007: Message edited by: Anil Kumble ]
I agree. Here's the link:
subject: Struts2: preselect checkbox
It's not a secret anymore!