2
* Copyright 1999-2002,2004 The Apache Software Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
package org.apache.struts.webapp.example;
21
import javax.servlet.http.HttpServletRequest;
23
import org.apache.struts.action.ActionError;
24
import org.apache.struts.action.ActionErrors;
25
import org.apache.struts.action.ActionMapping;
26
import org.apache.struts.validator.ValidatorForm;
30
* Form bean for the user registration page. This form has the following
31
* fields, with default values in square brackets:
33
* <li><b>action</b> - The maintenance action we are performing (Create,
35
* <li><b>fromAddress</b> - The EMAIL address of the sender, to be included
36
* on sent messages. [REQUIRED]
37
* <li><b>fullName</b> - The full name of the sender, to be included on
38
* sent messages. [REQUIRED]
39
* <li><b>password</b> - The password used by this user to log on.
40
* <li><b>password2</b> - The confirmation password, which must match
41
* the password when changing or setting.
42
* <li><b>replyToAddress</b> - The "Reply-To" address to be included on
43
* sent messages. [Same as from address]
44
* <li><b>username</b> - The registered username, which must be unique.
48
* @author Craig R. McClanahan
49
* @version $Revision: 1.3 $ $Date: 2004/03/08 02:49:52 $
52
public final class RegistrationForm extends ValidatorForm {
55
// ----------------------------------------------------- Instance Variables
59
* The maintenance action we are performing (Create or Edit).
61
private String action = "Create";
67
private String fromAddress = null;
73
private String fullName = null;
79
private String password = null;
83
* The confirmation password.
85
private String password2 = null;
89
* The reply to address.
91
private String replyToAddress = null;
98
private String username = null;
101
// ----------------------------------------------------------- Properties
105
* Return the maintenance action.
107
public String getAction() {
109
return (this.action);
115
* Set the maintenance action.
117
* @param action The new maintenance action.
119
public void setAction(String action) {
121
this.action = action;
127
* Return the from address.
129
public String getFromAddress() {
131
return (this.fromAddress);
137
* Set the from address.
139
* @param fromAddress The new from address
141
public void setFromAddress(String fromAddress) {
143
this.fromAddress = fromAddress;
149
* Return the full name.
151
public String getFullName() {
153
return (this.fullName);
161
* @param fullName The new full name
163
public void setFullName(String fullName) {
165
this.fullName = fullName;
171
* Return the password.
173
public String getPassword() {
175
return (this.password);
183
* @param password The new password
185
public void setPassword(String password) {
187
this.password = password;
193
* Return the confirmation password.
195
public String getPassword2() {
197
return (this.password2);
203
* Set the confirmation password.
205
* @param password The new confirmation password
207
public void setPassword2(String password2) {
209
this.password2 = password2;
215
* Return the reply to address.
217
public String getReplyToAddress() {
219
return (this.replyToAddress);
225
* Set the reply to address.
227
* @param replyToAddress The new reply to address
229
public void setReplyToAddress(String replyToAddress) {
231
this.replyToAddress = replyToAddress;
237
* Return the username.
239
public String getUsername() {
241
return (this.username);
249
* @param username The new username
251
public void setUsername(String username) {
253
this.username = username;
258
// --------------------------------------------------------- Public Methods
262
* Reset all properties to their default values.
264
* @param mapping The mapping used to select this instance
265
* @param request The servlet request we are processing
267
public void reset(ActionMapping mapping, HttpServletRequest request) {
269
this.action = "Create";
270
this.fromAddress = null;
271
this.fullName = null;
272
this.password = null;
273
this.password2 = null;
274
this.replyToAddress = null;
275
this.username = null;
281
* Validate the properties that have been set from this HTTP request,
282
* and return an <code>ActionErrors</code> object that encapsulates any
283
* validation errors that have been found. If no errors are found, return
284
* <code>null</code> or an <code>ActionErrors</code> object with no
285
* recorded error messages.
287
* @param mapping The mapping used to select this instance
288
* @param request The servlet request we are processing
290
public ActionErrors validate(ActionMapping mapping,
291
HttpServletRequest request) {
293
// Perform validator framework validations
294
ActionErrors errors = super.validate(mapping, request);
296
// Only need crossfield validations here
297
if (((password == null) && (password2 != null)) ||
298
((password != null) && (password2 == null)) ||
299
((password != null) && (password2 != null) &&
300
!password.equals(password2))) {
301
errors.add("password2",
302
new ActionError("error.password.match"));