- Struts 2 implements XWork framework for input validations
- Struts 2 validation framework separates the actual validation logic and application code
- It can handle both client side and server side validations
- For configuring the validation framework validators.xml file or annotation is used
- If validators.xml file is not present in class path, the default.xml present in com/opensymphony/xwork2/validator/validators/folder is used
- Data of the action class is validated using validate() method
Struts2 Framework Validator (Cont’d)
Validators Types
Field Validators
- Implemented on fields accessible using action
- Field validators are bound to individual fields and can display specific error messages for individual fields
Example: Field Validator

Non Field Validators
- Implemented at action level
- Non field validators are bound to action and display action specific message
Example: Non Field Validator

Struts2 Framework Validator (Cont’d)
Visitor Field Validators
- Implemented on model properties of the action
- Can validate simple object properties, collection of objects, arrays etc.
Example: Visitor Field Validator
