You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ian Beaumont <IB...@categoric.com> on 2002/02/13 17:41:05 UTC

Confused over check boxes

I've got a checkbox on a page.  It's initial state needs to be checked.  In
my form I have a boolean value for the check box.
It fails to detect correctly if the check box is set.  In my reset method I
set the check box to true (as this is the initial state), but the help says
"WARNING: In order to correctly recognize unchecked checkboxes, the
ActionForm bean associated with this form must include a statement setting
the corresponding boolean property to false in the reset() method."
How am I supposed to deal with this situation?
Thanks
Ian Beaumont

Re: Confused over check boxes

Posted by Nick Thomson <nt...@nothnbut.net>.
Try thinking of it this way.  For every JSP page 2 actions take place.  The
first action is used to populate the form bean and then control is passed to
the JSP page.  During this phase you can ignore reset and set your
properties as you need them.  The 2nd action is used to process the user's
responses.  This is where the reset() method is important to you.  Per the
HTML spec., unchecked boxes are not placed in the parameter list.
Therefore, if the reset method did not uncheck your checkbox for you, then
you would not have any way of determining if a user had uncheck any boxes.

Hope this helps.

----- Original Message -----
From: "Ian Beaumont" <IB...@categoric.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, February 13, 2002 10:41 AM
Subject: Confused over check boxes


> I've got a checkbox on a page.  It's initial state needs to be checked.
In
> my form I have a boolean value for the check box.
> It fails to detect correctly if the check box is set.  In my reset method
I
> set the check box to true (as this is the initial state), but the help
says
> "WARNING: In order to correctly recognize unchecked checkboxes, the
> ActionForm bean associated with this form must include a statement setting
> the corresponding boolean property to false in the reset() method."
> How am I supposed to deal with this situation?
> Thanks
> Ian Beaumont
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Confused over check boxes

Posted by Ted Husted <hu...@apache.org>.
The underlying problem is that if they uncheck the box, the browser will
not submit anything at all. The property will be absent from the
request. So you would have to write something in the validate method
that looked to see if the parameter was missing, and if it was turned
your box to false. This is a huge pain, but sadly, it's how HTML/HTTP
works. 

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Java Web Development with Struts.
-- Tel +1 585 737-3463.
-- Web http://www.husted.com/struts/

Ian Beaumont wrote:
> 
> I've got a checkbox on a page.  It's initial state needs to be checked.  In
> my form I have a boolean value for the check box.
> It fails to detect correctly if the check box is set.  In my reset method I
> set the check box to true (as this is the initial state), but the help says
> "WARNING: In order to correctly recognize unchecked checkboxes, the
> ActionForm bean associated with this form must include a statement setting
> the corresponding boolean property to false in the reset() method."
> How am I supposed to deal with this situation?
> Thanks
> Ian Beaumont

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>