File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Checkbox and Multibox validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Checkbox and Multibox validation" Watch "Checkbox and Multibox validation" New topic
Author

Checkbox and Multibox validation

Hiroyuki Suzuki
Greenhorn

Joined: Jul 25, 2007
Posts: 24
hello guys..Im new in struts programming..
Just need your help on this matter..

I already made validations using validation.xml and validation-rules.xml
for html:text..
Now, how will I validate my form for checkbox and multibox?
Can I include it in my validation.xml or separate process?

Please teach me...

Thank you!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
With a single checkbox, there's really nothing to validate: It's either checked or it isn't, and the fact that it's on the page at all usually means that both checked and unchecked are valid states for the checkbox. About the only case I can think of where you might want to validate a single checkbox would be where you expect someone to check the box to indicate that they "agree to the terms and conditions... blah blah blah.." just to satisfy some legal requirement. In this case, just apply the "required" rule, and it will only be valid if it's checked.

In the case of a multibox, or a series of checkboxes that share the same property name, you may want to validate that at least one of the boxes has been checked. In that case, simply apply the "required" rule for that property, and Struts will return an error if at least one of the boxes is not checked.
[ July 26, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Hiroyuki Suzuki
Greenhorn

Joined: Jul 25, 2007
Posts: 24
thank you so much for your reply...
so i can add the validation required for multibox and checkbox in my validation.xml same syntax with text/textarea?

arigatou!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Hiroyuki Suzuki:
so i can add the validation required for multibox and checkbox in my validation.xml same syntax with text/textarea?

Yes, that's right.
Hiroyuki Suzuki
Greenhorn

Joined: Jul 25, 2007
Posts: 24
hello again Merrill!

it working now! thanks for your help..
However, I have a new problem regarding order of checking..
here how it goes..
1. choose between the two radio buttons
2. if radio1 is choose, it will check 5 checkboxes(defined as multibox)
3. if checkbox1 is choose, it will check if text areas are filled-up..

here is my sample code
JSP:
contents of radio1


validation.xml


Can I make some flags in validation.xml?
I mean if radio1 is true, it will check the multibox..and if checkbox1 of that multibox is true, then it will check the textarea..

Thank you very mych again...
Arigatou!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
There is a "validwhen" rule that allows you to validate one field based on the value of another. I will tell you in advance that it doesn't cover every possibility. If you have a fairly complex scenario, I'd recommend that you just write a custom validation rule.

To find out more about how to use validwhen see the section entitled Designing Complex Validations with validwhen in this link
Hiroyuki Suzuki
Greenhorn

Joined: Jul 25, 2007
Posts: 24
Arigatou Merryl...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checkbox and Multibox validation