This page last changed on Dec 14, 2004 by casey.

Overview

Interceptors are objects that dynamically intercept Action invocations. They provide the developer with the opportunity to define code that can be executed before and/or after the execution of an action. They also have the ability to prevent an action from executing. Interceptors provide developers a way to encapulate common functionality in a re-usable form that can be applied to one or more Actions. See XW:Interceptors for further details. Below describes built in Webwork interceptors.

Webwork & XWork Interceptors

Interceptor classes are also defined using a key-value pair specified in the xwork configuration file. The names specified below come specified in webwork-default.xml. If you extend the webwork-default package, then you can use the names below. Otherwise they must be defined in your package with a name-class pair specified in the <interceptors> tag.
NameDescription
timerOutputs how long the action (including nested interceptors and view) takes to execute
loggerOutputs the name of the action
chainMakes the previous action's properties available to the current action. Commonly used together with <result type="chain"> (in the previous action). See Chaining Interceptor for more info
static-paramsSets the xwork.xml defined parameters onto the action. These are the <param> tags that are direct children of the <action> tag.
paramsSets the request parameters onto the action.
model-drivenIf the action implements ModelDriven, pushes the getModel() result onto the valuestack.
componentEnables and makes the components available to the Actions. Refer to components.xml
tokenChecks for valid token presence in action, prevents duplicate form submission
token-sessionSame as above, but storing the submitted data in session when handed an invalid token
validationPerforms validation using the validators defined in {Action}-validation.xml
workflowCalls the validate method in your action class. If action errors created then it returns the INPUT view.
servlet-configGive access to HttpServletRequest and HttpServletResponse (think twice before using this since this ties you to the Servlet api)
prepareIf the action implements Preparable, calls its prepare() method.
conversionError adds conversion errors from the ActionContext to the Action's field errors
fileUploadan interceptor that adds easy access to file upload support. See the javadoc for more info
execAndWaitan interceptor that executes the action in the background and then sends the user off to an intermediate waiting page. See: ExecuteAndWaitInterceptor for more info

Order of Interceptor Execution

Interceptors provide an excellent means to wrap before/after processing. The concept reduces code duplication (think AOP).
<interceptor-stack name="xaStack"> 
  <interceptor-ref name="thisWillRunFirstInterceptor"/>
  <interceptor-ref name="thisWillRunNextInterceptor"/>
  <interceptor-ref name="followedByThisInterceptor"/>
  <interceptor-ref name="thisWillRunLastInterceptor"/>
</interceptor-stack>

Note that some interceptors will interrupt the stack/chain/flow… so the order is very important.

Iterceptors implementing com.opensymphony.xwork.interceptor.PreResultListener will run after the Action executes its action method but before the Result executes
thisWillRunFirstInterceptor
  thisWillRunNextInterceptor
    followedByThisInterceptor
      thisWillRunLastInterceptor
        MyAction1
        MyAction2 (chain)
        MyPreResultListener  
        MyResult (result)
      thisWillRunLastInterceptor
    followedByThisInterceptor
  thisWillRunNextInterceptor
thisWillRunFirstInterceptor
Document generated by Confluence on Dec 14, 2004 16:36