com.opensymphony.webwork.interceptor
Class ScopeInterceptor

java.lang.Object
  extended by com.opensymphony.webwork.interceptor.ScopeInterceptor
All Implemented Interfaces:
Interceptor, PreResultListener, Serializable

public class ScopeInterceptor
extends Object
implements Interceptor, PreResultListener

This is designed to solve a few simple issues related to wizard-like functionality in WebWork. One of those issues is that some applications have a application-wide parameters commonly used, such pageLen (used for records per page). Rather than requiring that each action check if such parameters are supplied, this interceptor can look for specified parameters and pull them out of the session.

This works by setting listed properties at action start with values from session/application attributes keyed after the action's class, the action's name, or any supplied key. After action is executed all the listed properties are taken back and put in session or application context.

To make sure that each execution of the action is consistent it makes use of session-level locking. This way it guarantees that each action execution is atomic at the session level. It doesn't guarantee application level consistency however there has yet to be enough reasons to do so. Application level consistency would also be a big performance overkill.

Note that this interceptor takes a snapshot of action properties just before result is presented (using a PreResultListener), rather than after action is invoked. There is a reason for that: At this moment we know that action's state is "complete" as it's values may depend on the rest of the stack and specifically - on the values of nested interceptors.

Interceptor parameters:

Extending the interceptor:

There are no know extension points for this interceptor.

Example code:

 
 <!-- As the filter and orderBy parameters are common for all my browse-type actions,
      you can move control to the scope interceptor. In the session parameter you can list
      action properties that are going to be automatically managed over session. You can
      do the same for application-scoped variables-->
 <action name="someAction" class="com.examples.SomeAction">
     <interceptor-ref name="basicStack"/>
     <interceptor-ref name="hibernate"/>
     <interceptor-ref name="scope">
         <param name="session">filter,orderBy</param>
         <param name="autoCreateSession">true</param>
     </interceptor-ref>
     <result name="success">good_result.ftl</result>
 </action>
 
 

Author:
Mike Mosiewicz, Rainer Hermanns
See Also:
Serialized Form

Constructor Summary
ScopeInterceptor()
           
 
Method Summary
protected  void after(ActionInvocation invocation, String result)
           
protected  void before(ActionInvocation invocation)
           
 void beforeResult(ActionInvocation invocation, String resultCode)
          This callback method will be called after the Action execution and before the Result execution.
 void destroy()
          Called to let an interceptor clean up any resources it has allocated.
 String getSessionReset()
           
 String getType()
           
 void init()
          Called after an interceptor is created, but before any requests are processed using intercept , giving the Interceptor a chance to initialize any needed resources.
 String intercept(ActionInvocation invocation)
          Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the request by the ActionInvocation or to short-circuit the processing and just return a String return code.
 boolean isReset()
           
 void setApplication(String s)
           
 void setAutoCreateSession(String value)
           
 void setKey(String key)
           
 void setReset(boolean reset)
           
 void setSession(String s)
           
 void setSessionReset(String sessionReset)
           
 void setType(String type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScopeInterceptor

public ScopeInterceptor()
Method Detail

setApplication

public void setApplication(String s)

setSession

public void setSession(String s)

setAutoCreateSession

public void setAutoCreateSession(String value)

after

protected void after(ActionInvocation invocation,
                     String result)
              throws Exception
Throws:
Exception

before

protected void before(ActionInvocation invocation)
               throws Exception
Throws:
Exception

setKey

public void setKey(String key)

beforeResult

public void beforeResult(ActionInvocation invocation,
                         String resultCode)
Description copied from interface: PreResultListener
This callback method will be called after the Action execution and before the Result execution.

Specified by:
beforeResult in interface PreResultListener

getType

public String getType()

setType

public void setType(String type)

getSessionReset

public String getSessionReset()

setSessionReset

public void setSessionReset(String sessionReset)

destroy

public void destroy()
Description copied from interface: Interceptor
Called to let an interceptor clean up any resources it has allocated.

Specified by:
destroy in interface Interceptor

init

public void init()
Description copied from interface: Interceptor
Called after an interceptor is created, but before any requests are processed using intercept , giving the Interceptor a chance to initialize any needed resources.

Specified by:
init in interface Interceptor

intercept

public String intercept(ActionInvocation invocation)
                 throws Exception
Description copied from interface: Interceptor
Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the request by the ActionInvocation or to short-circuit the processing and just return a String return code.

Specified by:
intercept in interface Interceptor
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().

isReset

public boolean isReset()

setReset

public void setReset(boolean reset)

WebWork Project Page