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

Check Box Handling

Syed Saifuddin
Ranch Hand

Joined: Sep 01, 2003
Posts: 130
Using checkbox in struts is become eating an elephant for me. First of all setting default value as checked is difficult. And now when I did this using formbean as set the value of checkbox true in the constructor of formbean, A new problem arise. Now if I unchecked the box manually and then submit the box the value it set to the db is true rather false.

Any help in this regard is highly appreciateable.

Thank You
Syed Saifuddin

Thank You & Best Regards,

Syed Saifuddin,
Senior Software Engineer

SAP Oracle AIX & Java Training
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
All values controlled by a checkbox should be set to false in the reset() method of the form bean. If you need a particular checkbox to be shown as checked by default, set the value to true in the action class prior to forwarding to the JSP, not in the reset() method.

The problem here is that when a checkbox is unchecked, it does not send a value to the server when the form is submitted. Consequently, the setter on your ActionForm bean is not called. The only way around this quirk of HTML is to set all values controlled by checkboxes to false in the reset() method.

Consultant, Sima Solutions
Syed Saifuddin
Ranch Hand

Joined: Sep 01, 2003
Posts: 130
Thank You Merrill Higginson

You lead me to the solution. You are too good
I agree. Here's the link:
subject: Check Box Handling
It's not a secret anymore!