Struts Action 2 relies on a validation framework provided by [XWork] to enable the application of input validation rules to your Actions before they are executed. This section only provides the bare minimum to get you started and focuses on our extension of the XWork validators to support client-side validation.
There is also an option for Client Side (Javascript and/or AJAX) based validation, please see Client Side Validation for more information.
Using Annotations
Annotations can be used as an alternative to XML for validation.
Examples
- Basic Validation
- Client Validation
- AJAX Validation
- Using Field Validators
- Using Non Field Validators
- Using Visitor Field Validator
Bundled Validators
Note
When using a Field Validator, Field Validator Syntax is ALWAYS preferable than using the Plain Validator Syntax as it facilitates grouping of field-validators according to fields. This is very handy especially if a field needs to have many field-validators which is almost always the case. Examples: validatortypes
- required validator
- requiredstring validator
- int validator
- date validator
- expression validator
- fieldexpression validator
- email validator
- url validator
- visitor validator
- conversion validator
- stringlength validator
- regex validator
Registering Validators
This list declares all the validators that comes with the framework.
Note
Warning
Turning on Validation
Note: The default validationWorkflowStack already includes this.
You can turn off validation for a specific method by using the @SkipValidation annotation above your action method.