The XWork validation subsystem of the Struts2 framework that enables the application of input validation rules to Actions before they are executed.
The XWork validation framework used to run the validation rules on actions before executing the action. The validation rules in the action class could be exposed using annotations. The framework is supposed to extensive use of the XWork validators to support server-side and client-side validation.
The validators supplied by the XWork distribution (and any custom validators) come in two different flavors:
1. Plain Validators / Non-Field validators
2. FieldValidators
Plain Validators (such as the ExpressionValidator) perform validation checks that are not inherently tied to a single specified field.
FieldValidators (such as the EmailValidator) are designed to perform validation checks on a single field. They require that you specify a fieldname attribute in the -validation.xml
file. There are two different (but equivalent) XML syntaxes you can use to declare FieldValidators:
1. <validator>
2. <field-validator>
Non-Field-Validator The element allows you to declare both types of validators (either a plain Validator a field-specific FieldValidator).
Field-validator The <field-validator>
elements are basically the same as the <validator>
elements except that they inherit the fieldName attribute from the enclosing <field>
element. FieldValidators defined within a <field-validator>
element will have their fieldName automatically filled with the value of the parent <field>
element's fieldName attribute. The reason for this structure is to conveniently group the validators for a particular field under one element, otherwise the fieldName attribute would have to be repeated, over and over, for each individual <validator>
.