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