Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Validate CheckBoxes in a group using validation.xml

 
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
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • 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;
 
Hang a left on main. Then read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic