Save This Page
Home » xwork-2.1.1-src » com.opensymphony.xwork2.validator » [javadoc | source]
com.opensymphony.xwork2.validator
public class: ValidationInterceptor [javadoc | source]
java.lang.Object
   com.opensymphony.xwork2.interceptor.AbstractInterceptor
      com.opensymphony.xwork2.interceptor.MethodFilterInterceptor
         com.opensymphony.xwork2.validator.ValidationInterceptor

All Implemented Interfaces:
    Interceptor

This interceptor runs the action through the standard validation framework, which in turn checks the action against any validation rules (found in files such as ActionClass-validation.xml) and adds field-level and action-level error messages (provided that the action implements com.opensymphony.xwork2.ValidationAware ). This interceptor is often one of the last (or second to last) interceptors applied in a stack, as it assumes that all values have already been set on the action.

This interceptor does nothing if the name of the method being invoked is specified in the excludeMethods parameter. excludeMethods accepts a comma-delimited list of method names. For example, requests to foo!input.action and foo!back.action will be skipped by this interceptor if you set the excludeMethods parameter to "input, back".

The workflow of the action request does not change due to this interceptor. Rather, this interceptor is often used in conjuction with the workflow interceptor.

NOTE: As this method extends off MethodFilterInterceptor, it is capable of deciding if it is applicable only to selective methods in the action class. See MethodFilterInterceptor for more info.

Interceptor parameters:

Extending the interceptor:

There are no known extension points for this interceptor.

Example code:



<action name="someAction" class="com.examples.SomeAction">
<interceptor-ref name="params"/>
<interceptor-ref name="validation"/>
<interceptor-ref name="workflow"/>
<result name="success">good_result.ftl</result>
</action>

<-- in the following case myMethod of the action class will not
get validated -->
<action name="someAction" class="com.examples.SomeAction">
<interceptor-ref name="params"/>
<interceptor-ref name="validation">
<param name="excludeMethods">myMethod</param>
</interceptor-ref>
<interceptor-ref name="workflow"/>
<result name="success">good_result.ftl</result>
</action>

<-- in the following case only annotated methods of the action class will
be validated -->
<action name="someAction" class="com.examples.SomeAction">
<interceptor-ref name="params"/>
<interceptor-ref name="validation">
<param name="validateAnnotatedMethodOnly">true</param>
</interceptor-ref>
<interceptor-ref name="workflow"/>
<result name="success">good_result.ftl</result>
</action>



Fields inherited from com.opensymphony.xwork2.interceptor.MethodFilterInterceptor:
log,  excludeMethods,  includeMethods
Method from com.opensymphony.xwork2.validator.ValidationInterceptor Summary:
doBeforeInvocation,   doIntercept,   isValidateAnnotatedMethodOnly,   setActionValidatorManager,   setAlwaysInvokeValidate,   setDeclarative,   setProgrammatic,   setValidateAnnotatedMethodOnly
Methods from com.opensymphony.xwork2.interceptor.MethodFilterInterceptor:
applyInterceptor,   doIntercept,   getExcludeMethodsSet,   getIncludeMethodsSet,   intercept,   setExcludeMethods,   setIncludeMethods
Methods from com.opensymphony.xwork2.interceptor.AbstractInterceptor:
destroy,   init,   intercept
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.opensymphony.xwork2.validator.ValidationInterceptor Detail:
 protected  void doBeforeInvocation(ActionInvocation invocation) throws Exception 
 protected String doIntercept(ActionInvocation invocation) throws Exception 
 public boolean isValidateAnnotatedMethodOnly() 
    Gets if validate() should always be called or only per annotated method.
 public  void setActionValidatorManager(ActionValidatorManager mgr) 
 public  void setAlwaysInvokeValidate(String alwaysInvokeValidate) 
    Determines if Validateable 's validate() should always be invoked. Default to "true".
 public  void setDeclarative(boolean declarative) 
    Determines if validation based on annotations or xml should be performed. Defaults to "true".
 public  void setProgrammatic(boolean programmatic) 
    Determines if Validateable 's validate() should be called, as well as methods whose name that start with "validate". Defaults to "true".
 public  void setValidateAnnotatedMethodOnly(boolean validateAnnotatedMethodOnly) 
    Determine if validate() should always be called or only per annotated method. Default to false.