1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.webapp.example2;
19
20
21 import javax.servlet.http.HttpServletRequest;
22 import org.apache.struts.action.ActionMessage;
23 import org.apache.struts.action.ActionErrors;
24 import org.apache.struts.action.ActionMapping;
25 import org.apache.struts.validator.ValidatorForm;
26
27
28 /***
29 * Form bean for the user registration page. This form has the following
30 * fields, with default values in square brackets:
31 * <ul>
32 * <li><b>action</b> - The maintenance action we are performing (Create,
33 * Delete, or Edit).
34 * <li><b>fromAddress</b> - The EMAIL address of the sender, to be included
35 * on sent messages. [REQUIRED]
36 * <li><b>fullName</b> - The full name of the sender, to be included on
37 * sent messages. [REQUIRED]
38 * <li><b>password</b> - The password used by this user to log on.
39 * <li><b>password2</b> - The confirmation password, which must match
40 * the password when changing or setting.
41 * <li><b>replyToAddress</b> - The "Reply-To" address to be included on
42 * sent messages. [Same as from address]
43 * <li><b>username</b> - The registered username, which must be unique.
44 * [REQUIRED]
45 * </ul>
46 *
47 * @author Craig R. McClanahan
48 * @version $Rev: 421494 $ $Date: 2006-07-12 20:55:17 -0700 (Wed, 12 Jul 2006) $
49 */
50
51 public final class RegistrationForm extends ValidatorForm {
52
53
54
55
56
57 /***
58 * The maintenance action we are performing (Create or Edit).
59 */
60 private String action = "Create";
61
62
63 /***
64 * The from address.
65 */
66 private String fromAddress = null;
67
68
69 /***
70 * The full name.
71 */
72 private String fullName = null;
73
74
75 /***
76 * The password.
77 */
78 private String password = null;
79
80
81 /***
82 * The confirmation password.
83 */
84 private String password2 = null;
85
86
87 /***
88 * The reply to address.
89 */
90 private String replyToAddress = null;
91
92
93
94 /***
95 * The username.
96 */
97 private String username = null;
98
99
100
101
102
103 /***
104 * Return the maintenance action.
105 */
106 public String getAction() {
107
108 return (this.action);
109
110 }
111
112
113 /***
114 * Set the maintenance action.
115 *
116 * @param action The new maintenance action.
117 */
118 public void setAction(String action) {
119
120 this.action = action;
121
122 }
123
124
125 /***
126 * Return the from address.
127 */
128 public String getFromAddress() {
129
130 return (this.fromAddress);
131
132 }
133
134
135 /***
136 * Set the from address.
137 *
138 * @param fromAddress The new from address
139 */
140 public void setFromAddress(String fromAddress) {
141
142 this.fromAddress = fromAddress;
143
144 }
145
146
147 /***
148 * Return the full name.
149 */
150 public String getFullName() {
151
152 return (this.fullName);
153
154 }
155
156
157 /***
158 * Set the full name.
159 *
160 * @param fullName The new full name
161 */
162 public void setFullName(String fullName) {
163
164 this.fullName = fullName;
165
166 }
167
168
169 /***
170 * Return the password.
171 */
172 public String getPassword() {
173
174 return (this.password);
175
176 }
177
178
179 /***
180 * Set the password.
181 *
182 * @param password The new password
183 */
184 public void setPassword(String password) {
185
186 this.password = password;
187
188 }
189
190
191 /***
192 * Return the confirmation password.
193 */
194 public String getPassword2() {
195
196 return (this.password2);
197
198 }
199
200
201 /***
202 * Set the confirmation password.
203 *
204 * @param password2 The new confirmation password
205 */
206 public void setPassword2(String password2) {
207
208 this.password2 = password2;
209
210 }
211
212
213 /***
214 * Return the reply to address.
215 */
216 public String getReplyToAddress() {
217
218 return (this.replyToAddress);
219
220 }
221
222
223 /***
224 * Set the reply to address.
225 *
226 * @param replyToAddress The new reply to address
227 */
228 public void setReplyToAddress(String replyToAddress) {
229
230 this.replyToAddress = replyToAddress;
231
232 }
233
234
235 /***
236 * Return the username.
237 */
238 public String getUsername() {
239
240 return (this.username);
241
242 }
243
244
245 /***
246 * Set the username.
247 *
248 * @param username The new username
249 */
250 public void setUsername(String username) {
251
252 this.username = username;
253
254 }
255
256
257
258
259
260 /***
261 * Reset all properties to their default values.
262 *
263 * @param mapping The mapping used to select this instance
264 * @param request The servlet request we are processing
265 */
266 public void reset(ActionMapping mapping, HttpServletRequest request) {
267
268 this.action = "Create";
269 this.fromAddress = null;
270 this.fullName = null;
271 this.password = null;
272 this.password2 = null;
273 this.replyToAddress = null;
274 this.username = null;
275
276 }
277
278
279 /***
280 * Validate the properties that have been set from this HTTP request,
281 * and return an <code>ActionErrors</code> object that encapsulates any
282 * validation errors that have been found. If no errors are found, return
283 * <code>null</code> or an <code>ActionErrors</code> object with no
284 * recorded error messages.
285 *
286 * @param mapping The mapping used to select this instance
287 * @param request The servlet request we are processing
288 */
289 public ActionErrors validate(ActionMapping mapping,
290 HttpServletRequest request) {
291
292
293 ActionErrors errors = super.validate(mapping, request);
294
295
296 if (((password == null) && (password2 != null)) ||
297 ((password != null) && (password2 == null)) ||
298 ((password != null) && (password2 != null) &&
299 !password.equals(password2))) {
300 errors.add("password2",
301 new ActionMessage("error.password.match"));
302 }
303 return errors;
304
305 }
306
307
308 }