Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In other words, when you access a *.action URL, WebWork's ServletDispatcher proceeds to the invocation of the an action object. Before it is executed, however, the invocation can be intercepted by another object, that is hence called interceptor. To have an interceptor executed before (or after) a given action,

just configure xwork.xml properly, like the example below, taken from lesson 4.1.1:

Interceptor configuration from lesson 4.1.1:

...


<action name="formProcessing" class="lesson04_01_01.FormProcessingAction"> 
	<result name="input" type="dispatcher">ex01-index.jsp</result> 
	<result name="success" type="dispatcher">ex01-success.jsp</result> 
	<interceptor-ref name="validationWorkflowStack" /> 
</action> 

As you can see, lesson 4.1.1's formProcessing Action uses the validationWorkflowStack. That is an interceptor stack, which organizes a bunch of interceptors in the order in which they are to be executed. That stack is configured in webwork-default.xml, so all we have to do to use it is declare a <interceptor-ref /> under the action configuration or a <default-interceptor-ref />, under package configuration, as seen in lesson 3's first example:

Interceptor configuration from starter example:

...

  • timer: clocks how long the action (including nested interceptors and view) takes to execute;
  • logger: logs the action being executed;
  • chain: makes the previous action's properties available to the current action. Used to make action chaining (reference: Result Types);
  • static-params: sets the parameters defined in xwork.xml onto the action. These are the <param /> tags that are direct children of the <action /> tag;
  • params: sets the request (POST and GET) parameters onto the action class. We have seen an example of this in lesson 3 TODO;
  • model-driven: if the action implements ModelDriven, pushes the getModel() result onto the Value Stack;
  • component: enables and makes registered components available to the actions. (reference: IoC & Components);
  • token: checks for valid token presence in action, prevents duplicate form submission;
  • token-session: same as above, but storing the submitted data in session when handed an invalid token;
  • validation: performs validation using the validators defined in {Action}-validation.xml (reference: Validation). We've seen an example of this in lesson 4.1.1;
  • workflow: calls the validate method in your action class. If action errors created then it returns the INPUT view. Good to use together with the validation interceptor (reference: Validation);
  • servlet-config: give access to HttpServletRequest and HttpServletResponse (think twice before using this since this ties you to the Servlet API);
  • prepare: allows you to programmatic access to your Action class before the parameters are set on it.;
  • conversionError: Adds field errors if any type-conversion errors occurred.
  • execAndWait: Spawns a separate thread to execute the action
  • fileUpload: Sets uploaded files as action files (File objects)

In addition to the prepackaged interceptors, webwork-default.xml includes prepackaged
combinations of these interceptors in named interceptor stacks.

Building your own Interceptor

...

The xwork.xml configuration, the action class and the result page are pretty straightforward and require no further explanation.

Try the example!

Info
titleTODO

CHANGE THIS LINKS

...

...