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 Validate CheckBoxes in a group using validation.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validate CheckBoxes in a group using validation.xml" Watch "Validate CheckBoxes in a group using validation.xml" New topic
Author

Validate CheckBoxes in a group using validation.xml

Gayatri Ganesh
Ranch Hand

Joined: Dec 23, 2003
Posts: 143
Hi,

I have a jsp with 3 checkboxes and 1 textfield for email.
AT least 1 checkbox out of the 3 should be checked otherwise an error message should be displayed to the user.
I looked at the struts built-in validations but there does not seem to be any.
I was thinking of doing all validations in the validate() of the ActionForm, but in that case i will have to rewrite the whole validation for email which is provided by the validation-rules.xml.

Both the validations should be either in validation.xml or the validate() method, otherwise only 1 error msg i.e the validation in the validation.xml is displayed, the other validation related to the checkbox is not displayed.

Can anyone suggest a solution to this problem.

Thanks,
Gayatri
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Originally posted by Gayatri Ganesh:

Both the validations should be either in validation.xml or the validate() method, otherwise only 1 error msg i.e the validation in the validation.xml is displayed, the other validation related to the checkbox is not displayed.


That is not true. The call to super.validate() is what sets off the validation.xml's framework.

So if you do
ActionErrors errors = new ActionErrors();
errors.add(super.validate(mapping, request)); // validation.xml for email
if(noCheckboxWasSelected){
errors.add(... new error ...);
}
return errors;

it should work;


A good workman is known by his tools.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validate CheckBoxes in a group using validation.xml