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