webwork / docs / actionchaining.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <title>OpenSymphony Wiki (Offline Version) :: WebWork2 Documentation</title>
  <link type="text/css" href="main.css" rel="STYLESHEET"/>
  <div id="page-logo">
    <a href="index.html">WebWork2 Documentation</a>
    <div class="snip-title">
	  <h1 class="snip-name">Webwork - Why would I use Action Chaining?
<div id="snip-content" class="snip-content">

 <div class="snip-attachments"></div>
 The ActionChainResult in WebWork2 provides the ability to compose multiple Actions together to execute in a defined sequence or workflow. By applying the ActionChainResult as the result of your Action, like so:<p class="paragraph"/><div class="code"><pre>&#60;result name=<span class="xml&#45;quote">"success"</class> type=<span class="xml&#45;quote">"chain"</class>&#62;
    &#60;param name=<span class="xml&#45;quote">"actionName"</class>&#62;Bar&#60;/param&#62;
&#60;/result&#62;</pre></div><p class="paragraph"/>another Action in the same namespace (or the default "" namespace) can be executed after this Action (see <a href="http://wiki.opensymphony.com/space/XWork+Configuration">XWork Configuration</a>). An optional "namespace" parameter may also be added to specify an Action in a different namespace. The original parameters from the request and the ValueStack are passed in when this Action is chained to, so the chained to Action will be added on the ValueStack above the chained from Action. This allows the chained to Action to access the properties of the preceding Action(s) using the ValueStack, and also makes these properties available to the final result of the chain, such as the JSP or Velocity page.<p class="paragraph"/>If you need to copy the properties from your previous Actions in the chain to the current Action, you should apply the ChainingInterceptor (see <a href="http://wiki.opensymphony.com/space/XWork+Interceptors#Chaining">XWork Interceptors#Chaining</a>) which copies the properties of all objects on the ValueStack to the current target.<p class="paragraph"/>One common use of Action chaining is to provide lookup lists (like for a dropdown list of states, etc). Since these Actions get put on the ValueStack, these properties will be available in the view. This functionality can also be done using the ActionTag to execute an Action from the display page. In WW1.x Action chaining is often used to chain to a RedirectAction to redirect to another page after processing (in WW2 we have a redirect result).<p class="paragraph"/>Basically it's good when you have some reusable code you want to encapsulate&#8230; In WW2 if you use it a lot, you could make it an Interceptor, or use it as an Action with chaining. If you need to set up and use some properties from it, it needs to be an Action.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.