This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validate CheckBoxes in a group using validation.xml

 
Gayatri Ganesh
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic