KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > webapp > example > RegistrationForm


1 /*
2  * $Id: RegistrationForm.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19
20 package org.apache.struts.webapp.example;
21
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24
25 import org.apache.struts.action.ActionErrors;
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.action.ActionMessage;
28 import org.apache.struts.validator.ValidatorForm;
29
30
31 /**
32  * Form bean for the user registration page. This form has the following
33  * fields, with default values in square brackets:
34  * <ul>
35  * <li><b>action</b> - The maintenance action we are performing (Create,
36  * Delete, or Edit).
37  * <li><b>fromAddress</b> - The EMAIL address of the sender, to be included
38  * on sent messages. [REQUIRED]
39  * <li><b>fullName</b> - The full name of the sender, to be included on
40  * sent messages. [REQUIRED]
41  * <li><b>password</b> - The password used by this user to log on.
42  * <li><b>password2</b> - The confirmation password, which must match
43  * the password when changing or setting.
44  * <li><b>replyToAddress</b> - The "Reply-To" address to be included on
45  * sent messages. [Same as from address]
46  * <li><b>username</b> - The registered username, which must be unique.
47  * [REQUIRED]
48  * </ul>
49  *
50  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
51  */

52
53 public final class RegistrationForm extends ValidatorForm {
54
55
56     // ----------------------------------------------------- Instance Variables
57

58
59     /**
60      * The maintenance action we are performing (Create or Edit).
61      */

62     private String JavaDoc action = "Create";
63
64
65     /**
66      * The from address.
67      */

68     private String JavaDoc fromAddress = null;
69
70
71     /**
72      * The full name.
73      */

74     private String JavaDoc fullName = null;
75
76
77     /**
78      * The password.
79      */

80     private String JavaDoc password = null;
81
82
83     /**
84      * The confirmation password.
85      */

86     private String JavaDoc password2 = null;
87
88
89     /**
90      * The reply to address.
91      */

92     private String JavaDoc replyToAddress = null;
93
94
95
96     /**
97      * The username.
98      */

99     private String JavaDoc username = null;
100
101
102     // ----------------------------------------------------------- Properties
103

104
105     /**
106      * Return the maintenance action.
107      */

108     public String JavaDoc getAction() {
109
110     return (this.action);
111
112     }
113
114
115     /**
116      * Set the maintenance action.
117      *
118      * @param action The new maintenance action.
119      */

120     public void setAction(String JavaDoc action) {
121
122         this.action = action;
123
124     }
125
126
127     /**
128      * Return the from address.
129      */

130     public String JavaDoc getFromAddress() {
131
132     return (this.fromAddress);
133
134     }
135
136
137     /**
138      * Set the from address.
139      *
140      * @param fromAddress The new from address
141      */

142     public void setFromAddress(String JavaDoc fromAddress) {
143
144         this.fromAddress = fromAddress;
145
146     }
147
148
149     /**
150      * Return the full name.
151      */

152     public String JavaDoc getFullName() {
153
154     return (this.fullName);
155
156     }
157
158
159     /**
160      * Set the full name.
161      *
162      * @param fullName The new full name
163      */

164     public void setFullName(String JavaDoc fullName) {
165
166         this.fullName = fullName;
167
168     }
169
170
171     /**
172      * Return the password.
173      */

174     public String JavaDoc getPassword() {
175
176     return (this.password);
177
178     }
179
180
181     /**
182      * Set the password.
183      *
184      * @param password The new password
185      */

186     public void setPassword(String JavaDoc password) {
187
188         this.password = password;
189
190     }
191
192
193     /**
194      * Return the confirmation password.
195      */

196     public String JavaDoc getPassword2() {
197
198     return (this.password2);
199
200     }
201
202
203     /**
204      * Set the confirmation password.
205      *
206      * @param password2 The new confirmation password
207      */

208     public void setPassword2(String JavaDoc password2) {
209
210         this.password2 = password2;
211
212     }
213
214
215     /**
216      * Return the reply to address.
217      */

218     public String JavaDoc getReplyToAddress() {
219
220     return (this.replyToAddress);
221
222     }
223
224
225     /**
226      * Set the reply to address.
227      *
228      * @param replyToAddress The new reply to address
229      */

230     public void setReplyToAddress(String JavaDoc replyToAddress) {
231
232         this.replyToAddress = replyToAddress;
233
234     }
235
236
237     /**
238      * Return the username.
239      */

240     public String JavaDoc getUsername() {
241
242     return (this.username);
243
244     }
245
246
247     /**
248      * Set the username.
249      *
250      * @param username The new username
251      */

252     public void setUsername(String JavaDoc username) {
253
254         this.username = username;
255
256     }
257
258
259     // --------------------------------------------------------- Public Methods
260

261
262     /**
263      * Reset all properties to their default values.
264      *
265      * @param mapping The mapping used to select this instance
266      * @param request The servlet request we are processing
267      */

268     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
269
270         this.action = "Create";
271         this.fromAddress = null;
272         this.fullName = null;
273         this.password = null;
274         this.password2 = null;
275         this.replyToAddress = null;
276         this.username = null;
277
278     }
279
280
281     /**
282      * Validate the properties that have been set from this HTTP request,
283      * and return an <code>ActionErrors</code> object that encapsulates any
284      * validation errors that have been found. If no errors are found, return
285      * <code>null</code> or an <code>ActionErrors</code> object with no
286      * recorded error messages.
287      *
288      * @param mapping The mapping used to select this instance
289      * @param request The servlet request we are processing
290      */

291     public ActionErrors validate(ActionMapping mapping,
292                                  HttpServletRequest JavaDoc request) {
293
294         // Perform validator framework validations
295
ActionErrors errors = super.validate(mapping, request);
296
297         // Only need crossfield validations here
298
if (!password.equals(password2)) {
299             errors.add("password2",
300                        new ActionMessage("error.password.match"));
301         }
302         return errors;
303
304     }
305
306
307 }
308
Popular Tags