1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.webapp.dispatch;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22 import org.apache.struts.actions.ActionDispatcher;
23 import org.apache.struts.actions.EventActionDispatcher;
24 import org.apache.struts.action.Action;
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionForward;
27 import org.apache.struts.action.ActionMapping;
28 import org.apache.struts.action.ActionMessage;
29 import org.apache.struts.action.ActionMessages;
30
31 /***
32 * Example EventActionDispatcher.
33 *
34 * @version $Rev: 421488 $ $Date: 2006-07-12 20:43:08 -0700 (Wed, 12 Jul 2006) $
35 */
36 public class EventActionDispatcherExample extends Action {
37
38 private ActionDispatcher dispatcher
39 = new EventActionDispatcher(this);
40
41 private int fooCount;
42 private int barCount;
43
44 /***
45 * Execute method.
46 *
47 * @param mapping The ActionMapping used to select this instance
48 * @param form The optional ActionForm bean for this request
49 * @param request The servlet request we are processing
50 * @param response The servlet response we are creating
51 *
52 * @exception Exception if business logic throws an exception
53 */
54 public ActionForward execute(ActionMapping mapping,
55 ActionForm form,
56 HttpServletRequest request,
57 HttpServletResponse response)
58 throws Exception {
59
60 return dispatcher.execute(mapping, form, request, response);
61
62 }
63
64 /***
65 * Example "foo" method.
66 *
67 * @param mapping The ActionMapping used to select this instance
68 * @param form The optional ActionForm bean for this request
69 * @param request The servlet request we are processing
70 * @param response The servlet response we are creating
71 *
72 * @exception Exception if business logic throws an exception
73 */
74 public ActionForward doFoo(ActionMapping mapping,
75 ActionForm form,
76 HttpServletRequest request,
77 HttpServletResponse response)
78 throws Exception {
79
80 fooCount++;
81
82 ActionMessages messages = new ActionMessages();
83 messages.add("foo", new ActionMessage("count.foo.message", fooCount+""));
84 saveMessages(request, messages);
85
86 return (mapping.findForward("success"));
87
88 }
89
90 /***
91 * Example "bar" method.
92 *
93 * @param mapping The ActionMapping used to select this instance
94 * @param form The optional ActionForm bean for this request
95 * @param request The servlet request we are processing
96 * @param response The servlet response we are creating
97 *
98 * @exception Exception if business logic throws an exception
99 */
100 public ActionForward doBar(ActionMapping mapping,
101 ActionForm form,
102 HttpServletRequest request,
103 HttpServletResponse response)
104 throws Exception {
105 barCount++;
106
107 ActionMessages messages = new ActionMessages();
108 messages.add("bar", new ActionMessage("count.bar.message", barCount+""));
109 saveMessages(request, messages);
110
111 return (mapping.findForward("success"));
112
113 }
114
115 }