You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Shaun Whyte <sw...@opaltelecom.co.uk> on 2002/07/29 18:18:50 UTC

Pre-checking checkboxes

Hi all

Question about <html:checkbox ... /> tags...

In an ActionForm, to set a checkbox attribute from a form in a jsp, the
attribute must be a boolean, and because the forms setCheckBoxValue(boolean)
method is only called if the checkbox is checked, it must be initialised to
false in the reset() method to cater for non-checked checkboxes.

If I want to pre-check a checkbox when the form is initially displayed, then
the only way I know of doing this is to use another boolean attribute in my
ActionForm to hold its initial value (set to true), but the "real" checkbox
attribute (one which I will be looking at in my Action class) will be
initialised to false.  If the user leaves the checkbox checked then the set
method will be called which will actually set my "real" attribute to true.
If they uncheck the checkbox, then no call is made and my "real" attribute
remains false.

However, if the user makes an error on the form, and the form is returned
with the validation errors listed at the top, because the form always gets
the "initial" attribute from the ActionForm (not the "real" value), it is
always true, even if they unchecked the checkbox.

Is there a way around this, or an easier way of doing the whole checkbox
thing?

Thanks in advance,
Shaun.


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