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