Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.opensymphony.xwork2.interceptor
Class PrepareInterceptor

    java.lang.Object
      com.opensymphony.xwork2.interceptor.AbstractInterceptor
          com.opensymphony.xwork2.interceptor.PrepareInterceptor

All Implemented Interfaces:
  Interceptor, Serializable

    public class PrepareInterceptor

extends AbstractInterceptor

This interceptor calls prepare() on actions which implement `Preparable`. This interceptor is very useful for any situation where you need to ensure some logic runs before the actual execute method runs.

A typical use of this is to run some logic to load an object from the database so that when parameters are set they can be set on this object. For example, suppose you have a User object with two properties: id and name. Provided that the params interceptor is called twice (once before and once after this interceptor), you can load the User object using the id property, and then when the second params interceptor is called the parameter user.name will be set, as desired, on the actual object loaded from the database. See the example for more info.

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

Interceptor parameters:

- alwaysInvokePrepare - Default to true. If true, prepare will always be invoked, otherwise it will not.

Extending the interceptor:

There are no known extension points to this interceptor.

Example code:

     <!-- Calls the params interceptor twice, allowing you to
           pre-load data for the second time parameters are set -->
      <action name="someAction" class="com.examples.SomeAction">
          <interceptor-ref name="params"/>
          <interceptor-ref name="prepare"/>
          <interceptor-ref name="basicStack"/>
          <result name="success">good_result.ftl</result>
      </action>

Date: Nov 5, 2003 2:33:11 AM

Author:
  Jason Carreira, Philip Luppens, tm_jee
See Also:
  `Preparable`, Serialized Form

Field Summary
`private static Log` | `_log`
`private static String` | `ALT_PREPARE_PREFIX`
`private boolean` | `alwaysInvokePrepare`
`private static String` | `PREPARE_PREFIX`
`private static long` | `serialVersionUID`

Constructor Summary
`PrepareInterceptor()`

Method Summary
`String` | `intercept(ActionInvocation invocation)` Override to handle interception
`void` | `setAlwaysInvokePrepare(String alwaysInvokePrepare)`

Methods inherited from class com.opensymphony.xwork2.interceptor.AbstractInterceptor
`destroy, init`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### serialVersionUID

    private static final long serialVersionUID

See Also:
  Constant Field Values

### _log

    private static final Log _log

### PREPARE_PREFIX

    private static final String PREPARE_PREFIX

See Also:
  Constant Field Values

### ALT_PREPARE_PREFIX

    private static final String ALT_PREPARE_PREFIX

See Also:
  Constant Field Values

### alwaysInvokePrepare

    private boolean alwaysInvokePrepare

Constructor Detail

### PrepareInterceptor

    public PrepareInterceptor()

Method Detail

### setAlwaysInvokePrepare

    public void setAlwaysInvokePrepare(String alwaysInvokePrepare)

### intercept

    public String intercept(ActionInvocation invocation)
                     throws Exception

  Description copied from class: `AbstractInterceptor`
  Override to handle interception

  Specified by:
    `intercept` in interface `Interceptor`
  Specified by:
    `intercept` in class `AbstractInterceptor`
  Returns:
    the return code, either returned from `ActionInvocation.invoke()`, or from the interceptor itself.
  Throws:
    `Exception` - any system-level error, as defined in `Action.execute()`.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2007 OpenSymphony. All Rights Reserved.