1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.struts.tiles;
20
21 import java.io.IOException;
22
23 import javax.servlet.ServletContext;
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
30 /***
31 * Struts wrapper implementation of Controller. This implementation wraps an
32 * <code>Action</code> in a <code>Controller</code>.
33 */
34 public class ActionController implements Controller {
35
36 /***
37 * Struts action wrapped.
38 */
39 private Action action = null;
40
41 /***
42 * Constructor.
43 *
44 * @param action Action to be wrapped.
45 */
46 public ActionController(Action action) {
47 this.action = action;
48 }
49
50 /***
51 * Method associated to a tile and called immediately before tile is
52 * included. This implementation calls a Struts Action. No servlet is
53 * set by this method.
54 *
55 * @param tileContext Current tile context.
56 * @param request Current request.
57 * @param response Current response.
58 * @param servletContext Current servlet context.
59 */
60 public void perform(
61 ComponentContext tileContext,
62 HttpServletRequest request,
63 HttpServletResponse response,
64 ServletContext servletContext)
65 throws ServletException, IOException {
66
67 try {
68 action.execute(null, null, request, response);
69
70 } catch (Exception e) {
71 throw new ServletException(e);
72 }
73 }
74
75 /***
76 * @see org.apache.struts.tiles.Controller#execute(org.apache.struts.tiles.ComponentContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.ServletContext)
77 */
78 public void execute(
79 ComponentContext tileContext,
80 HttpServletRequest request,
81 HttpServletResponse response,
82 ServletContext servletContext)
83 throws Exception {
84
85 this.action.execute(null, null, request, response);
86
87 }
88 }