Apache Struts 2 Plugin Registry > Home > Scope Plugin |
Name | Scope Plugin |
---|---|
Publisher | Apache Software Foundation |
License | Open Source (ASL2) |
Version | 1.0.4 |
Homepage | http://code.google.com/p/struts2scopeplugin/ |
Download | http://code.google.com/p/struts2scopeplugin/downloads/list |
Source Code | http://code.google.com/p/struts2scopeplugin/source |
Example | http://struts2scopeplugin.googlecode.com/svn/trunk/example/ |
The Scope plugin implements JBoss Seam-style scoped bijection and conversation management. It allows a user to declaratively define action properties that should be injected via the session before an action executes or properties that should be pushed out to the session after an action executes. It also allows conversations to be defined so that session-scoped variables can be managed better.
See http://code.google.com/p/struts2plugin-maven-repo/ if you use maven.
For non-maven users, this plugin can be installed by copying the plugin jar into your application's /WEB-INF/lib directory.
The scope plugin allows declarative scope management of action properties. Action properties can be scoped to one of several predefined scope. The predefined scopes are:
The scope management functionality is provided by an interceptor which needs to be added to your action's interceptor stack:
<interceptor name="bean-scope" class="com.googlecode.scopeplugin.ScopeInterceptor" />
The following example shows how a session managed bean can be automatically be moved from the session to an action property before the action executes and moved from the action to the session after the action executes.
public class ExampleAction { @In (scope=ScopeType.SESSION) @Out (scope=ScopeType.SESSION) private ExampleBean exampleBean; ... }
The next example shows how a conversation can be created and destroyed. Currently only a single active conversation is supported. A conversation will automatically be created for variables defined as CONVERSATION scope.
public class ExampleAction extends ActionSupport { @In (scope=ScopeType.CONVERSATION) @Out (scope=ScopeType.CONVERSATION) private ExampleBean exampleBean; ... @Begin public String startConversation() { exampleBean = new ExampleBean(); return SUCCESS; } public String doStuffinConversation() { return SUCCESS; } @End public String endConversation() { return SUCCESS; } ... }