You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by pu...@netsol.co.in on 2007/01/30 16:05:26 UTC
Struts 1.3.5 - Radio Button validation
Hi all,
Can you please tell me whether I can validate a set of radio buttons so that
atleast one of them is checked, using the struts validation.xml? Is there a
pre-defined validator method (like required) defined for that or will I have
to write a custom validator method?
Thanks.
-Pushkar
Re: Struts 1.3.5 - Radio Button validation
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Laurie,
Laurie Harper wrote:
> Actually, assuming it's a radio button group that maps to a single
> property, you probably just need the 'required' validation to ensure
> that property has a value. You should only need 'validwhen' if there are
> multiple properties involved, or if you need to express complex
> constraints on a single property.
Sorry, you're right. The OP's question threw me off by saying that he
wanted to ensure that at least one of the choices was picked. I didn't
realize he was talking about radio buttons where you either get /one/
thing or nothing.
If he's got checkboxes (which is what I was thinking, even though he
clearly said radio buttons) or multiple unrelated radio buttons,
validwhen may be necessary. But probably not in this case.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFv+wp9CaO5/Lv0PARAqcrAKCWIwsRrhj/CYjhF291BYGv4NjjIACgpYL8
EdGlL713saF+yNQrt6AyeaE=
=OJQI
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 1.3.5 - Radio Button validation
Posted by Laurie Harper <la...@holoweb.net>.
Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Pushkar,
>
> pushkar.p@netsol.co.in wrote:
>> Can you please tell me whether I can validate a set of radio buttons so that
>> atleast one of them is checked, using the struts validation.xml? Is there a
>> pre-defined validator method (like required) defined for that or will I have
>> to write a custom validator method?
>
> You want to look into using the "validwhen" validator, which requires
> some reading. Check out this page
> (http://struts.apache.org/1.3.5/faqs/validator.html) and read the
> section titled "Designing Complex Validations with validwhen"
>
> You'll want a field set up with a "validwhen" test like:
>
> ((*this* != null) or (otherField != null)) or (anotherField != null) ...
Actually, assuming it's a radion button group that maps to a single
property, you probably just need the 'required' validation to ensure
that property has a value. You should only need 'validwhen' if there are
multiple properties involved, or if you need to express complex
constraints on a single property.
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 1.3.5 - Radio Button validation
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Pushkar,
pushkar.p@netsol.co.in wrote:
> Can you please tell me whether I can validate a set of radio buttons so that
> atleast one of them is checked, using the struts validation.xml? Is there a
> pre-defined validator method (like required) defined for that or will I have
> to write a custom validator method?
You want to look into using the "validwhen" validator, which requires
some reading. Check out this page
(http://struts.apache.org/1.3.5/faqs/validator.html) and read the
section titled "Designing Complex Validations with validwhen"
You'll want a field set up with a "validwhen" test like:
((*this* != null) or (otherField != null)) or (anotherField != null) ...
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFv4KH9CaO5/Lv0PARAuo3AKCN+yenAN3RTWjjkmt2bkxeQ/A34wCcCOXA
/nMAgdUEnqEbrzw1/Ako6cs=
=ciOF
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org