Struts validation could be a pain. This how-to should help. ................................................................................. How to enable struts validation: Make sure you have the following: 1) ApplicationResources.properties file with keys/values for standard validators (at least - errors.required) 2) struts-config.xml file should contain the reference to this resource file for message-resources node. 3) struts-config plug-in node should contain validator Plugin className="org.apache.struts.validator.ValidatorPlugIn" 4) The plugin should have set-property with name pathnames that corresponds to validator files (such as /WEB-INF/validator-rules.xml and /WEB-INF/validation.xml) 5) Action Validation vs. Form Validation. Alternative solutions: Solution A: - Form Validation: validation.xml should contain form with name that corresponds to form-bean name in struts-config. - Form Bean or its Parent should inherit org.apache.struts.validator.ValidatorForm class Solution B (povides more flexibility):- - Form Validation: validation.xml should contain form with name that corresponds to actions path name in struts-config. - Form Bean or its Parent should inherit org. apache.struts.validator.ValidatorActionForm. 6) The form should have a field with property that corresponds to field name we want to validate. Nested properties are okay. 7) This field should have a 'depends' attribute that corresponds to the validator name mentioned in /WEB-INF/validator-rules.xml (i.e. 'required') 8) This field should have an arg0 node with attribute key that corresponds to existing key in application resource file 9) in action-mapping: 'input' attribute of action should reference to jsp page with validated form and validate should be set to true. 12) jsp page should contains <html:errors /> (or its substitute) File Compatibility: 1) Make sure the validation-rules.xml and commons-validator.jar match. The xml version and jars implementation version need to be compatible 2) Make sure your struts.jar version is compatible with the commons-validator.jar 3 ) Compabitly issues will usually result in validation not working and no errors or warnings to trace the problem. To avoid issues, simply do not attempt to reuse other's validation.xml, validation-rules.xml, and commons-validator.jar files. Only use files that are packaged with your struts distribution zip/tar file.
--------------------------------- Blab-away for as little as 1¢/min. Make PC-to-Phone Calls using Yahoo! Messenger with Voice.