001: /*
002: * $Id: RegistrationForm.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package org.apache.struts.webapp.example2;
023:
024: import javax.servlet.http.HttpServletRequest;
025: import org.apache.struts.action.ActionMessage;
026: import org.apache.struts.action.ActionErrors;
027: import org.apache.struts.action.ActionMapping;
028: import org.apache.struts.validator.ValidatorForm;
029:
030: /**
031: * Form bean for the user registration page. This form has the following
032: * fields, with default values in square brackets:
033: * <ul>
034: * <li><b>action</b> - The maintenance action we are performing (Create,
035: * Delete, or Edit).
036: * <li><b>fromAddress</b> - The EMAIL address of the sender, to be included
037: * on sent messages. [REQUIRED]
038: * <li><b>fullName</b> - The full name of the sender, to be included on
039: * sent messages. [REQUIRED]
040: * <li><b>password</b> - The password used by this user to log on.
041: * <li><b>password2</b> - The confirmation password, which must match
042: * the password when changing or setting.
043: * <li><b>replyToAddress</b> - The "Reply-To" address to be included on
044: * sent messages. [Same as from address]
045: * <li><b>username</b> - The registered username, which must be unique.
046: * [REQUIRED]
047: * </ul>
048: *
049: * @author Craig R. McClanahan
050: * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
051: */
052:
053: public final class RegistrationForm extends ValidatorForm {
054:
055: // ----------------------------------------------------- Instance Variables
056:
057: /**
058: * The maintenance action we are performing (Create or Edit).
059: */
060: private String action = "Create";
061:
062: /**
063: * The from address.
064: */
065: private String fromAddress = null;
066:
067: /**
068: * The full name.
069: */
070: private String fullName = null;
071:
072: /**
073: * The password.
074: */
075: private String password = null;
076:
077: /**
078: * The confirmation password.
079: */
080: private String password2 = null;
081:
082: /**
083: * The reply to address.
084: */
085: private String replyToAddress = null;
086:
087: /**
088: * The username.
089: */
090: private String username = null;
091:
092: // ----------------------------------------------------------- Properties
093:
094: /**
095: * Return the maintenance action.
096: */
097: public String getAction() {
098:
099: return (this .action);
100:
101: }
102:
103: /**
104: * Set the maintenance action.
105: *
106: * @param action The new maintenance action.
107: */
108: public void setAction(String action) {
109:
110: this .action = action;
111:
112: }
113:
114: /**
115: * Return the from address.
116: */
117: public String getFromAddress() {
118:
119: return (this .fromAddress);
120:
121: }
122:
123: /**
124: * Set the from address.
125: *
126: * @param fromAddress The new from address
127: */
128: public void setFromAddress(String fromAddress) {
129:
130: this .fromAddress = fromAddress;
131:
132: }
133:
134: /**
135: * Return the full name.
136: */
137: public String getFullName() {
138:
139: return (this .fullName);
140:
141: }
142:
143: /**
144: * Set the full name.
145: *
146: * @param fullName The new full name
147: */
148: public void setFullName(String fullName) {
149:
150: this .fullName = fullName;
151:
152: }
153:
154: /**
155: * Return the password.
156: */
157: public String getPassword() {
158:
159: return (this .password);
160:
161: }
162:
163: /**
164: * Set the password.
165: *
166: * @param password The new password
167: */
168: public void setPassword(String password) {
169:
170: this .password = password;
171:
172: }
173:
174: /**
175: * Return the confirmation password.
176: */
177: public String getPassword2() {
178:
179: return (this .password2);
180:
181: }
182:
183: /**
184: * Set the confirmation password.
185: *
186: * @param password2 The new confirmation password
187: */
188: public void setPassword2(String password2) {
189:
190: this .password2 = password2;
191:
192: }
193:
194: /**
195: * Return the reply to address.
196: */
197: public String getReplyToAddress() {
198:
199: return (this .replyToAddress);
200:
201: }
202:
203: /**
204: * Set the reply to address.
205: *
206: * @param replyToAddress The new reply to address
207: */
208: public void setReplyToAddress(String replyToAddress) {
209:
210: this .replyToAddress = replyToAddress;
211:
212: }
213:
214: /**
215: * Return the username.
216: */
217: public String getUsername() {
218:
219: return (this .username);
220:
221: }
222:
223: /**
224: * Set the username.
225: *
226: * @param username The new username
227: */
228: public void setUsername(String username) {
229:
230: this .username = username;
231:
232: }
233:
234: // --------------------------------------------------------- Public Methods
235:
236: /**
237: * Reset all properties to their default values.
238: *
239: * @param mapping The mapping used to select this instance
240: * @param request The servlet request we are processing
241: */
242: public void reset(ActionMapping mapping, HttpServletRequest request) {
243:
244: this .action = "Create";
245: this .fromAddress = null;
246: this .fullName = null;
247: this .password = null;
248: this .password2 = null;
249: this .replyToAddress = null;
250: this .username = null;
251:
252: }
253:
254: /**
255: * Validate the properties that have been set from this HTTP request,
256: * and return an <code>ActionErrors</code> object that encapsulates any
257: * validation errors that have been found. If no errors are found, return
258: * <code>null</code> or an <code>ActionErrors</code> object with no
259: * recorded error messages.
260: *
261: * @param mapping The mapping used to select this instance
262: * @param request The servlet request we are processing
263: */
264: public ActionErrors validate(ActionMapping mapping,
265: HttpServletRequest request) {
266:
267: // Perform validator framework validations
268: ActionErrors errors = super .validate(mapping, request);
269:
270: // Only need crossfield validations here
271: if (((password == null) && (password2 != null))
272: || ((password != null) && (password2 == null))
273: || ((password != null) && (password2 != null) && !password
274: .equals(password2))) {
275: errors.add("password2", new ActionMessage(
276: "error.password.match"));
277: }
278: return errors;
279:
280: }
281:
282: }
|