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.HashMap;
24 import java.util.Map;
25
26 import jakarta.servlet.http.HttpServletRequest;
27 import jakarta.servlet.http.HttpServletResponse;
28
29 import org.apache.struts.action.ActionForm;
30 import org.apache.struts.action.ActionForward;
31 import org.apache.struts.action.ActionMapping;
32 import org.apache.struts.action.ActionMessage;
33 import org.apache.struts.action.ActionMessages;
34 import org.apache.struts.extras.actions.LookupDispatchAction;
35
36
37
38
39
40
41 public class LookupDispatchExampleAction extends LookupDispatchAction {
42 private static final long serialVersionUID = 6423904873036854367L;
43
44 private HashMap<String, String> keyMethodMap = new HashMap<>();
45 private int fooCount;
46 private int barCount;
47
48
49
50
51 public LookupDispatchExampleAction() {
52 keyMethodMap.put("button.foo.label", "doFoo");
53 keyMethodMap.put("button.bar.label", "doBar");
54 }
55
56
57
58
59
60
61
62
63
64
65
66 public ActionForward doFoo(ActionMapping mapping,
67 ActionForm form,
68 HttpServletRequest request,
69 HttpServletResponse response)
70 throws Exception {
71
72 fooCount++;
73
74 ActionMessages messages = new ActionMessages();
75 messages.add("foo", new ActionMessage("count.foo.message", fooCount+""));
76 saveMessages(request, messages);
77
78 return (mapping.findForward("success"));
79
80 }
81
82
83
84
85
86
87
88
89
90
91
92 public ActionForward doBar(ActionMapping mapping,
93 ActionForm form,
94 HttpServletRequest request,
95 HttpServletResponse response)
96 throws Exception {
97 barCount++;
98
99 ActionMessages messages = new ActionMessages();
100 messages.add("bar", new ActionMessage("count.bar.message", barCount+""));
101 saveMessages(request, messages);
102
103 return (mapping.findForward("success"));
104
105 }
106
107
108
109
110
111
112 protected Map<String, String> getKeyMethodMap() {
113 return keyMethodMap;
114 }
115 }