1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts.webapp.validator;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26 import javax.servlet.http.HttpSession;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.struts.action.Action;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34 import org.apache.struts.action.ActionMessages;
35
36
37
38
39
40
41 public final class MultiRegistrationAction extends Action {
42
43
44
45
46 private Log log = LogFactory.getFactory().getInstance(this.getClass().getName());
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 public ActionForward execute(
63 ActionMapping mapping,
64 ActionForm form,
65 HttpServletRequest request,
66 HttpServletResponse response)
67 throws Exception {
68
69
70 RegistrationForm info = (RegistrationForm) form;
71
72
73
74 if (isCancelled(request)) {
75 if (log.isInfoEnabled()) {
76 log.info(
77 " "
78 + mapping.getAttribute()
79 + " - Registration transaction was cancelled");
80 }
81
82 removeFormBean(mapping, request);
83
84 return mapping.findForward("success");
85 }
86
87 ActionMessages errors = info.validate(mapping, request);
88
89 if (errors != null && errors.isEmpty()) {
90 if (info.getPage() == 1)
91 return mapping.findForward("input2");
92
93 if (info.getPage() == 2)
94 return mapping.findForward("success");
95
96 } else {
97 this.saveErrors(request, errors);
98
99 if (info.getPage() == 1){
100 return mapping.findForward("input" + info.getPage());
101 }
102
103 if (info.getPage() == 2){
104 return mapping.findForward("input" + info.getPage());
105 }
106 }
107
108 return mapping.findForward("input1");
109 }
110
111
112
113
114
115
116
117 protected void removeFormBean(
118 ActionMapping mapping,
119 HttpServletRequest request) {
120
121
122 if (mapping.getAttribute() != null) {
123 if ("request".equals(mapping.getScope())) {
124 request.removeAttribute(mapping.getAttribute());
125 } else {
126 HttpSession session = request.getSession();
127 session.removeAttribute(mapping.getAttribute());
128 }
129 }
130 }
131 }