KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > app3 > LogonForm


1 /*
2  * Copyright 2003 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 package examples.app3;
18
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import org.apache.struts.action.ActionError;
22 import org.apache.struts.action.ActionErrors;
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionMapping;
25
26
27 /**
28  * Form bean for the user profile page.
29  * This form has the following fields,
30  * with default values in square brackets:
31  * <ul>
32  * <li><b>password</b> - Entered password value
33  * <li><b>username</b> - Entered username value
34  * </ul>
35  *
36  * @author Ted Husted
37  * @version $Revision: 1.2 $ $Date: 2004/02/20 12:42:50 $
38  */

39
40 public final class LogonForm extends ActionForm
41 {
42
43
44
45
46     // ------------------------------------------------ Instance Variables
47

48
49     /**
50      * The password.
51      */

52     private String JavaDoc password = null;
53
54
55     /**
56      * The username.
57      */

58     private String JavaDoc username = null;
59
60
61     // ------------------------------------------------------ Properties
62

63     /**
64      * Return the password.
65      */

66     public String JavaDoc getPassword()
67     {
68
69         return (this.password);
70
71     }
72
73
74     /**
75      * Set the password.
76      *
77      * @param password The new password
78      */

79     public void setPassword(String JavaDoc password)
80     {
81
82         this.password = password;
83
84     }
85
86
87     /**
88      * Return the username.
89      */

90     public String JavaDoc getUsername()
91     {
92
93         return (this.username);
94
95     }
96
97
98     /**
99      * Set the username.
100      *
101      * @param username The new username
102      */

103     public void setUsername(String JavaDoc username)
104     {
105
106         this.username = username;
107
108     }
109
110
111     // -------------------------------------------------- Public Methods
112

113
114     /**
115      * Reset all properties to their default values.
116      *
117      * @param mapping The mapping used to select this instance
118      * @param request The servlet request we are processing
119      */

120     public void reset(ActionMapping mapping,
121         HttpServletRequest JavaDoc request)
122     {
123
124         setPassword(null);
125         setUsername(null);
126
127     }
128
129
130     /**
131      * Ensure that both fields have been input.
132      *
133      * @param mapping The mapping used to select this instance
134      * @param request The servlet request we are processing
135      */

136     public ActionErrors validate(ActionMapping mapping,
137                                  HttpServletRequest JavaDoc request)
138     {
139
140         ActionErrors errors = new ActionErrors();
141
142         if ((username == null) || (username.length() < 1))
143             errors.add("username", new ActionError("error.username.required"));
144
145         if ((password == null) || (password.length() < 1))
146             errors.add("password", new ActionError("error.password.required"));
147
148         return errors;
149
150     }
151
152 } // End LogonForm
153
Popular Tags