1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts.tiles.actions;
23
24 import javax.servlet.ServletException;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27
28 import org.apache.struts.action.Action;
29 import org.apache.struts.action.ActionForm;
30 import org.apache.struts.action.ActionForward;
31 import org.apache.struts.action.ActionMapping;
32 import org.apache.struts.tiles.ComponentContext;
33
34 /**
35 * Base class for Tiles Actions.
36 * This class has the same role as Struts Action. It provides a method execute(...)
37 * called when action is invoked. The difference is, that the execute() method takes
38 * an additional parameter : tile context.
39 * This class extends Struts Action. Subclasses should override
40 * execute(ComponentContext ...) method instead of Struts
41 * execute(ActionMapping ...) method.
42 * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
43 */
44 public abstract class TilesAction extends Action {
45
46 /**
47 * Original Struts Action's method.
48 * Retrieve current Tile context and call TilesAction execute method.
49 * Do not overload this method!
50 *
51 * @param mapping The ActionMapping used to select this instance.
52 * @param form The optional ActionForm bean for this request (if any).
53 * @param request The HTTP request we are processing.
54 * @param response The HTTP response we are creating.
55 *
56 * @exception Exception if the application business logic throws
57 * an exception
58 * @since Struts 1.1
59 */
60 public ActionForward execute(
61 ActionMapping mapping,
62 ActionForm form,
63 HttpServletRequest request,
64 HttpServletResponse response)
65 throws Exception {
66
67
68 ComponentContext context = ComponentContext.getContext(request);
69 if (context == null) {
70 throw new ServletException(
71 "Can't find Tile context for '"
72 + this.getClass().getName()
73 + "'. TilesAction subclasses must be called from a Tile");
74 }
75
76 return this.execute(context, mapping, form, request, response);
77 }
78
79 /**
80 * Process the specified HTTP request and create the corresponding HTTP
81 * response (or forward to another web component that will create it),
82 * with provision for handling exceptions thrown by the business logic.
83 * <br>
84 * Override this method to provide functionality.
85 *
86 * @param context The current Tile context, containing Tile attributes.
87 * @param mapping The ActionMapping used to select this instance.
88 * @param form The optional ActionForm bean for this request (if any).
89 * @param request The HTTP request we are processing.
90 * @param response The HTTP response we are creating.
91 *
92 * @exception Exception if the application business logic throws
93 * an exception
94 * @since Struts 1.1
95 */
96 public ActionForward execute(
97 ComponentContext context,
98 ActionMapping mapping,
99 ActionForm form,
100 HttpServletRequest request,
101 HttpServletResponse response)
102 throws Exception {
103
104 return null;
105 }
106
107 }