Validate CheckBoxes in a group using validation.xml
Gayatri Ganesh
Ranch Hand
Joined: Dec 23, 2003
Posts: 143
posted
0
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.
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;