Validator-Rules.xml File in Struts – Struts Tutorial

Validator-rules.xml file contains the following details:-

  • Default error messages validator rules
  • The class name, method names where the java code of validator rules reside….
  • The .jsp file names where the java script code of validator rules reside.
  • Various other details of validator rules

Note: – programmer just needs to arrange this file in Struts application. There is no need of editing this file.

The default error messages of validator rules are:-

  • Error.required = {0} is required
  • Error.email = {0} is invalid email
  • Error.date = {0} is not a date

{n}—none

Argument values are error-messages should be supplied by the programmer to complete the error messages with respect to the form components.

Example: – {0} is required message of required validator rule:-becomes: user-name is required when it is applied on username property(textbox) becomes: address is required when it is applied on address property (textbox)

Programmer uses validation.xml :-

a)      To configure his choce validator rule on form bean properties to perform form validation.

b)      Supplies {n} argument values for default error messages of validator rules.

c)       Provides instruction to vlalidator plug-in to generate the neccary javacode, javascript code based on validator rules that are configured on form bean class properties.

  • Is order to work with validator plug-in supplied validator rules our form bean class must extend from    org.apache.Struts.validator.validatorForm class (this class is sub class of ActionForm class).          

                    – org.apache.Struts.validator.ValidatorForm
                    –  org.apache.Struts.action.ActionForm

  • The form bean class that extends from regular Action class cannot work with validator plug-in based validations.
  • If “validate ()” method of our form bean class executes programmatic form validation will take place.
  • If validate() of our form bean class related super class (validate () of predefined validateForm class) executes then the  validator plugin based declarative form validation takes place based on the configuration done in validation.xml file because this method can activate validator plug-in.

Leave a Reply

Your email address will not be published. Required fields are marked *