If, by defaulting to true, you mean setting it to true when the page is
displayed, yes, you can do that. In your Action, set the property in your
form bean to true, and the checkbox will be displayed checked.

When the form is submitted, Struts will call your form bean's reset()
method, where you should set the property to false. If the checkbox was
checked when the form was submitted, there will be a query parameter
corresponding to it, and Struts will set the form bean property to true. If
the checkbox was not checked, there will be no corresponding query
parameter, so Struts will not set the property at all. The property will
then be false - as set by your reset() method - which is correct.

Hope this helps.

--
Martin Cooper


----- Original Message -----
From: "Rod Schmidt" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, June 16, 2001 10:55 PM
Subject: Re: <html:checkbox>


> Does this mean you can't default a checkbox to true? If you can, how do
you
> do it?
>
> Thanks,
> Rod Schmidt
>
> ----- Original Message -----
> From: "Ted Husted" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, June 15, 2001 5:45 PM
> Subject: Re: <html:checkbox>
>
>
> > They are actually "cached" in the request. It's just that with boolean
> > checkboxes, you should reset them them to false first, or there are side
> > effects. You really, really don't have to do anything else.
> >
> > It's important to remember that there is not a direct connection between
> > the HTML form and Struts. Everything has to go through HTTP. When the
> > form is submitted, all the properties are sent as parameters to the
> > request by HTTP. Struts then "catches" them and puts them back into the
> > ActionForm.
> >
> > What can happen with checkboxes is that if they get unchecked, the
> > browser won't send them back, and so Struts has no way to set them true
> > or false. By setting them to false when the form is initialized and to
> > false again when the form is reset, you get consistent results.
> > Otherwise, if they unchecked the box, and the browser didn't send it
> > back, the setting on your box may be indeterminate.
> >
> > Mike Thompson wrote:
> > >
> > > So this means that I have to cache the original state of all my
checkbox
> > > referenced vars so I can set them back in the reset method? :(
> > >     --m
> >
>


Reply via email to