01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.dispatcher;
06:
07: import java.util.Map;
08:
09: import com.opensymphony.webwork.interceptor.FlashInterceptor;
10: import com.opensymphony.xwork.ActionInvocation;
11:
12: /**
13: * <!-- START SNIPPET: description -->
14: * A flash result, that save the current action into the http session before
15: * invoking <code>super.doExecute(...)</code>, which actually just do
16: * a redirect to a specific location just as a normal {@link ServletRedirectResult}
17: * would.
18: * <!-- END SNIPPET: description -->
19: *
20: * <!-- START SNIPPET: params -->
21: * <ul>
22: * key - The key under which current action is stored in Http Session. Default to
23: * {@link FlashInterceptor#DEFAULT_KEY} which is the string '__flashAction'
24: * </ul>
25: * <!-- END SNIPPET: params -->
26: *
27: * <pre>
28: * <!-- START SNIPPET: example -->
29: *
30: * <action name="store">
31: * <result type="flash"</redirectToSomeWhere.jsp</result>
32: * </action>
33: * <action name="retrieve">
34: * <interceptor-ref name="flash">
35: * <param name="operation">Retrieve</param>
36: * </interceptor-ref>
37: * <interceptor-ref name="defaultStack" />
38: * <result>pageWhereWeNeedFlashActionStored.jsp</result>
39: * </action>
40: *
41: * <!-- END SNIPPET: example -->
42: * </pre>
43: *
44: *
45: * @author Patrick Lightbody
46: * @version $Date: 2006-12-11 13:57:12 +0100 (Mon, 11 Dec 2006) $ $Id: FlashResult.java 2758 2006-12-11 12:57:12Z tmjee $
47: */
48: public class FlashResult extends ServletRedirectResult {
49:
50: private static final long serialVersionUID = -8956841683709714038L;
51:
52: private String key = FlashInterceptor.DEFAULT_KEY;
53:
54: /**
55: * A flash result, that save the current action into the http session before
56: * invoking <code>super.doExecute(...)</code>.
57: *
58: * @see com.opensymphony.webwork.dispatcher.ServletRedirectResult#doExecute(java.lang.String, com.opensymphony.xwork.ActionInvocation)
59: */
60: protected void doExecute(String finalLocation,
61: ActionInvocation invocation) throws Exception {
62:
63: // before we redirect, let's save the state in to the session
64: Object action = invocation.getAction();
65: Map session = invocation.getInvocationContext().getSession();
66: session.put(FlashInterceptor.DEFAULT_KEY, action);
67:
68: super .doExecute(finalLocation, invocation);
69: }
70:
71: /**
72: * Set the key used to store the current action in http session.
73: * @param key
74: */
75: public void setKey(String key) {
76: this .key = key;
77: }
78:
79: /**
80: * Get the key used to store the current action in http session.
81: * @return String
82: */
83: public String getKey() {
84: return key;
85: }
86:
87: }
|