Apache Struts 2 Documentation > Home > Guides > Core Developers Guide > Interceptors > Workflow Interceptor
Added by digi9ten, last edited by Philip Luppens on Feb 10, 2007  (view change) show comment

An interceptor that does some basic validation workflow before allowing the interceptor chain to continue.

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 order of execution in the workflow is:

  1. If the action being executed implements Validateable, the action's Validateable#validate() validate method is called.
  2. Next, if the action implements ValidationAware, the action's ValidationAware#hasErrors() hasErrors method is called. If this method returns true, this interceptor stops the chain from continuing and immediately returns Action#INPUT

Note: if the action doesn't implement either interface, this interceptor effectively does nothing. This interceptor is often used with the validation interceptor. However, it does not have to be, especially if you wish to write all your validation rules by hand in the validate() method rather than in XML files.

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.

Update: Added logic to execute a validate{MethodName} and then conditionally followed than a general validate method, depending on the 'alwaysInvokeValidate' parameter/property which is by default set to true. This allows us to run some validation logic based on the method name we specify in the ActionProxy. For example, you can specify a validateInput() method that will be run before the invocation of the input method.

In DefaultWorkflowInterceptor

applies only when action implements com.opensymphony.xwork2.Validateable

  1. if the action class have validate{MethodName}(), it will be invoked
  2. else if the action class have validateDo{MethodName}(), it will be invoked
  3. no matter if 1] or 2] is performed, if alwaysInvokeValidate property of the interceptor is "true" (which is by default "true"), validate() will be invoked.

Parameters

  • alwaysInvokeValidate - Default to true. If true validate() method will always be invoked, otherwise it will not.
  • inputResultName - Default to "input". Determine the result name to be returned when an action / field error is found.

Extending the Interceptor

There are no known extension points for this interceptor.

Examples

<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 this case myMethod of the action class will not pass through 
       the workflow process -->
<action name="someAction" class="com.examples.SomeAction">
    <interceptor-ref name="params"/>
    <interceptor-ref name="validation"/>
    <interceptor-ref name="workflow">
        <param name="excludeMethods">myMethod</param>
    </interceptor-ref name="workflow">
    <result name="success">good_result.ftl</result>
</action>

<-- In this case, the result named "error" will be used when 
       an action / field error is found -->
<action name="someAction" class="com.examples.SomeAction">
    <interceptor-ref name="params"/>
    <interceptor-ref name="validation"/>
    <interceptor-ref name="workflow">
       <param name="inputResultName">error</param>
    </interceptor-ref>
    <result name="success">good_result.ftl</result>
</action>