Struts 2 validation is configured via XML or annotations. Manual validation in the action is also possible, and may be combined with XML - and annotation-driven validation.
Validation also depends on both the "validation
" and "workflow
" interceptors (both are included in the default interceptor stack). The "validation
" interceptor does the validation itself and creates a list of field-specific errors. The "workflow
" interceptor checks for the presence of validation errors: if any are found, it returns the "input" result (by default), taking the user back to the form which contained the validation errors.
...
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 |
...
Wiki Markup |
---|
{snippet:id=javadoc|javadoc=true|url=resources.com.opensymphony.xwork2.validator/ValidatorFactory.java} |
...
The default interceptor stack, "defaultStack", already has validation turned on. When creating your own interceptor-stack be sure to include both the "validation
" and "workflow
" interceptors. From struts-default.xml
:
...