~ubuntu-branches/ubuntu/trusty/libstruts1.2-java/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/struts-faces/src/example/org/apache/struts/webapp/example/RegistrationForm.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2004-11-19 15:35:25 UTC
  • Revision ID: james.westby@ubuntu.com-20041119153525-mdu08a76z4zo67xt
Tags: upstream-1.2.4
ImportĀ upstreamĀ versionĀ 1.2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 1999-2002,2004 The Apache Software Foundation.
 
3
 * 
 
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
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
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.
 
15
 */
 
16
 
 
17
 
 
18
package org.apache.struts.webapp.example;
 
19
 
 
20
 
 
21
import javax.servlet.http.HttpServletRequest;
 
22
 
 
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;
 
27
 
 
28
 
 
29
/**
 
30
 * Form bean for the user registration page.  This form has the following
 
31
 * fields, with default values in square brackets:
 
32
 * <ul>
 
33
 * <li><b>action</b> - The maintenance action we are performing (Create,
 
34
 *     Delete, or Edit).
 
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.
 
45
 *     [REQUIRED]
 
46
 * </ul>
 
47
 *
 
48
 * @author Craig R. McClanahan
 
49
 * @version $Revision: 1.3 $ $Date: 2004/03/08 02:49:52 $
 
50
 */
 
51
 
 
52
public final class RegistrationForm extends ValidatorForm  {
 
53
 
 
54
 
 
55
    // ----------------------------------------------------- Instance Variables
 
56
 
 
57
 
 
58
    /**
 
59
     * The maintenance action we are performing (Create or Edit).
 
60
     */
 
61
    private String action = "Create";
 
62
 
 
63
 
 
64
    /**
 
65
     * The from address.
 
66
     */
 
67
    private String fromAddress = null;
 
68
 
 
69
 
 
70
    /**
 
71
     * The full name.
 
72
     */
 
73
    private String fullName = null;
 
74
 
 
75
 
 
76
    /**
 
77
     * The password.
 
78
     */
 
79
    private String password = null;
 
80
 
 
81
 
 
82
    /**
 
83
     * The confirmation password.
 
84
     */
 
85
    private String password2 = null;
 
86
 
 
87
 
 
88
    /**
 
89
     * The reply to address.
 
90
     */
 
91
    private String replyToAddress = null;
 
92
 
 
93
 
 
94
 
 
95
    /**
 
96
     * The username.
 
97
     */
 
98
    private String username = null;
 
99
 
 
100
 
 
101
    // ----------------------------------------------------------- Properties
 
102
 
 
103
 
 
104
    /**
 
105
     * Return the maintenance action.
 
106
     */
 
107
    public String getAction() {
 
108
 
 
109
        return (this.action);
 
110
 
 
111
    }
 
112
 
 
113
 
 
114
    /**
 
115
     * Set the maintenance action.
 
116
     *
 
117
     * @param action The new maintenance action.
 
118
     */
 
119
    public void setAction(String action) {
 
120
 
 
121
        this.action = action;
 
122
 
 
123
    }
 
124
 
 
125
 
 
126
    /**
 
127
     * Return the from address.
 
128
     */
 
129
    public String getFromAddress() {
 
130
 
 
131
        return (this.fromAddress);
 
132
 
 
133
    }
 
134
 
 
135
 
 
136
    /**
 
137
     * Set the from address.
 
138
     *
 
139
     * @param fromAddress The new from address
 
140
     */
 
141
    public void setFromAddress(String fromAddress) {
 
142
 
 
143
        this.fromAddress = fromAddress;
 
144
 
 
145
    }
 
146
 
 
147
 
 
148
    /**
 
149
     * Return the full name.
 
150
     */
 
151
    public String getFullName() {
 
152
 
 
153
        return (this.fullName);
 
154
 
 
155
    }
 
156
 
 
157
 
 
158
    /**
 
159
     * Set the full name.
 
160
     *
 
161
     * @param fullName The new full name
 
162
     */
 
163
    public void setFullName(String fullName) {
 
164
 
 
165
        this.fullName = fullName;
 
166
 
 
167
    }
 
168
 
 
169
 
 
170
    /**
 
171
     * Return the password.
 
172
     */
 
173
    public String getPassword() {
 
174
 
 
175
        return (this.password);
 
176
 
 
177
    }
 
178
 
 
179
 
 
180
    /**
 
181
     * Set the password.
 
182
     *
 
183
     * @param password The new password
 
184
     */
 
185
    public void setPassword(String password) {
 
186
 
 
187
        this.password = password;
 
188
 
 
189
    }
 
190
 
 
191
 
 
192
    /**
 
193
     * Return the confirmation password.
 
194
     */
 
195
    public String getPassword2() {
 
196
 
 
197
        return (this.password2);
 
198
 
 
199
    }
 
200
 
 
201
 
 
202
    /**
 
203
     * Set the confirmation password.
 
204
     *
 
205
     * @param password The new confirmation password
 
206
     */
 
207
    public void setPassword2(String password2) {
 
208
 
 
209
        this.password2 = password2;
 
210
 
 
211
    }
 
212
 
 
213
 
 
214
    /**
 
215
     * Return the reply to address.
 
216
     */
 
217
    public String getReplyToAddress() {
 
218
 
 
219
        return (this.replyToAddress);
 
220
 
 
221
    }
 
222
 
 
223
 
 
224
    /**
 
225
     * Set the reply to address.
 
226
     *
 
227
     * @param replyToAddress The new reply to address
 
228
     */
 
229
    public void setReplyToAddress(String replyToAddress) {
 
230
 
 
231
        this.replyToAddress = replyToAddress;
 
232
 
 
233
    }
 
234
 
 
235
 
 
236
    /**
 
237
     * Return the username.
 
238
     */
 
239
    public String getUsername() {
 
240
 
 
241
        return (this.username);
 
242
 
 
243
    }
 
244
 
 
245
 
 
246
    /**
 
247
     * Set the username.
 
248
     *
 
249
     * @param username The new username
 
250
     */
 
251
    public void setUsername(String username) {
 
252
 
 
253
        this.username = username;
 
254
 
 
255
    }
 
256
 
 
257
 
 
258
    // --------------------------------------------------------- Public Methods
 
259
 
 
260
 
 
261
    /**
 
262
     * Reset all properties to their default values.
 
263
     *
 
264
     * @param mapping The mapping used to select this instance
 
265
     * @param request The servlet request we are processing
 
266
     */
 
267
    public void reset(ActionMapping mapping, HttpServletRequest request) {
 
268
 
 
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;
 
276
 
 
277
    }
 
278
 
 
279
 
 
280
    /**
 
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.
 
286
     *
 
287
     * @param mapping The mapping used to select this instance
 
288
     * @param request The servlet request we are processing
 
289
     */
 
290
    public ActionErrors validate(ActionMapping mapping,
 
291
                                 HttpServletRequest request) {
 
292
 
 
293
        // Perform validator framework validations
 
294
        ActionErrors errors = super.validate(mapping, request);
 
295
 
 
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"));
 
303
        }
 
304
        return errors;
 
305
 
 
306
    }
 
307
 
 
308
 
 
309
}