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