On Sat, 16 Jun 2001, Rod Schmidt wrote:
> Does this mean you can't default a checkbox to true? If you can, how do you
> do it?
>
When you create the ActionForm bean instance, set the corresponding
property to true. You can do this in a couple of ways:
* Initialize the instance variable to true inside the bean as you
declare it. That way, this checkbox will *always* be initialized
to checked.
* Create the form bean yourself in an action (instead of letting Struts
do it automatically), and call the setFoo(true) method on it.
The Struts example application uses the latter technique, for example, on
the SubscriptionForm bean. In the Edit Subscription action, the form bean
is created and the state of the autoConnect property is copied from the
underlying database bean.
Note that, no matter *what* you initialize it to, you must always call
setFoo(false) in the reset() method.
> Thanks,
> Rod Schmidt
>
Craig
> ----- 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
> >
>
>