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 java.util.Map;
21 import java.util.HashMap;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24 import org.apache.struts.actions.LookupDispatchAction;
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 LookupDispatchAction.
33 *
34 * @version $Rev: 421488 $ $Date: 2006-07-12 20:43:08 -0700 (Wed, 12 Jul 2006) $
35 */
36 public class LookupDispatchExampleAction extends LookupDispatchAction {
37
38 private Map keyMethodMap = new HashMap();
39 private int fooCount;
40 private int barCount;
41
42 /***
43 * Constructor - populate the key method map.
44 */
45 public LookupDispatchExampleAction() {
46 keyMethodMap.put("button.foo.label", "doFoo");
47 keyMethodMap.put("button.bar.label", "doBar");
48 }
49
50 /***
51 * Example "foo" method.
52 *
53 * @param mapping The ActionMapping used to select this instance
54 * @param form The optional ActionForm bean for this request
55 * @param request The servlet request we are processing
56 * @param response The servlet response we are creating
57 *
58 * @exception Exception if business logic throws an exception
59 */
60 public ActionForward doFoo(ActionMapping mapping,
61 ActionForm form,
62 HttpServletRequest request,
63 HttpServletResponse response)
64 throws Exception {
65
66 fooCount++;
67
68 ActionMessages messages = new ActionMessages();
69 messages.add("foo", new ActionMessage("count.foo.message", fooCount+""));
70 saveMessages(request, messages);
71
72 return (mapping.findForward("success"));
73
74 }
75
76 /***
77 * Example "bar" method.
78 *
79 * @param mapping The ActionMapping used to select this instance
80 * @param form The optional ActionForm bean for this request
81 * @param request The servlet request we are processing
82 * @param response The servlet response we are creating
83 *
84 * @exception Exception if business logic throws an exception
85 */
86 public ActionForward doBar(ActionMapping mapping,
87 ActionForm form,
88 HttpServletRequest request,
89 HttpServletResponse response)
90 throws Exception {
91 barCount++;
92
93 ActionMessages messages = new ActionMessages();
94 messages.add("bar", new ActionMessage("count.bar.message", barCount+""));
95 saveMessages(request, messages);
96
97 return (mapping.findForward("success"));
98
99 }
100
101 /***
102 * Provides the mapping from resource key to method name.
103 *
104 * @return Resource key / method name map.
105 */
106 protected Map getKeyMethodMap() {
107 return keyMethodMap;
108 }
109
110 }