You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

If you don't know already, WebWork uses XWork as its foundation, which does provide a validation framework to help you apply input validation rules to your Actions before they are executed. This section provide only enough details to help you get started but always refer to Validation Framework for more information.

Register validators

Validators must be registered with the ValidatorFactory. This may either be done programmatically, using the registerValidator(String name, Class clazz) static method of the ValidatorFactory, or by putting a file name validators.xml in the root of the classpath (/WEB-INF/classes) with a structure like this:

<validators>
    <validator name="required" class="com.opensymphony.xwork.validator.validators.RequiredFieldValidator"/>
    <validator name="requiredstring" class="com.opensymphony.webwork.validators.JavaScriptRequiredStringValidator"/>
    <validator name="int" class="com.opensymphony.webwork.validators.JavaScriptIntRangeFieldValidator"/>
    <validator name="date" class="com.opensymphony.webwork.validators.JavaScriptDateRangeFieldValidator"/>
    <validator name="expression" class="com.opensymphony.xwork.validator.validators.ExpressionValidator"/>
    <validator name="fieldexpression" class="com.opensymphony.xwork.validator.validators.FieldExpressionValidator"/>
    <validator name="email" class="com.opensymphony.webwork.validators.JavaScriptEmailValidator"/>
    <validator name="url" class="com.opensymphony.webwork.validators.JavaScriptURLValidator"/>
    <validator name="visitor" class="com.opensymphony.webwork.validators.JavaScriptVisitorFieldValidator"/>
    <validator name="conversion" class="com.opensymphony.xwork.validator.validators.ConversionErrorFieldValidator"/>
</validators>

Turn on Validation

All that is required to enable validation for an Action is to put the ValidationInterceptor in the interceptor refs of the action (see xwork.xml) like so:

<interceptor name="validator" class="com.opensymphony.xwork.validator.ValidationInterceptor"/>

Note: The default *validationWorkflowStack" already includes this.

Specify what and how to validate

  1. Per Action class
  2. Per Action alias
  3. Per package
  • No labels