On Tue, 8 May 2001, Spencer Smith wrote:

> 
> I know.  Struts doesn't handle unchecked boxes very well.  In fact, it
> doesn't understand them at all.
> 
> What you do is grab the current value from the DB display it, and then
> manually set the value to false from either a Reset() action in your FORM or
> directly from your JSP.
> 
> If you don't manually set the value to false, it will always save as True.
> 

The place to do this "manually set the value to false" is in the
reset() method of your form bean.  If you do this, everything will work as
expected.

The underlying cause of this is the way that browsers work.  If a checkbox
is checked, the controller servlet sees something like
"mycheckbox=on".  However, if the checkbox is unchecked, the controller
servlet sees *nothing* at all.  Setting boolean properties to false in the
reset() method works, because Struts will always call reset() before
populating the form bean properties -- thus, after population is complete
the boolean property will be true if the checkbox was checked, and false
if the checkbox was unchecked.

Craig McClanahan

Reply via email to