KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > struts > forms > UserForm


1 package hero.struts.forms;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4 import org.apache.struts.action.ActionError;
5 import org.apache.struts.action.ActionErrors;
6 import org.apache.struts.action.ActionForm;
7 import org.apache.struts.action.ActionMapping;
8
9
10 /**
11  * Form bean for the BnUser. This form has the following fields,
12  * with default values in square brackets:
13  * <ul>
14  * <li><b>name</b> - The name of the user. [REQUIRED]
15  * <li><b>password</b> - The password for this user. [REQUIRED]
16  * <li><b>email</b> - The email [REQUIRED]
17  * </ul>
18  *
19  * @author Miguel Valdes Faura
20  * @version $Revision: 1.1 $ $Date: 2004/07/30 14:57:57 $
21  */

22
23 public final class UserForm extends ActionForm {
24
25
26 // =================================================== Instance Variables
27

28
29     /**
30      * The user name
31      */

32     private String JavaDoc name = null;
33
34
35     /**
36      * The password of the user
37      */

38
39     private String JavaDoc password = null;
40
41     /**
42      * The email of the user
43      */

44
45          private String JavaDoc email = null;
46
47     /**
48      * The jabber address of the user
49      */

50
51          private String JavaDoc jabber = null;
52
53
54     // =========================================================== Properties
55

56
57     /**
58      * Return the name
59      */

60     public String JavaDoc getName() {
61
62     return (this.name);
63
64     }
65
66     /**
67      * Set the name
68      *
69      */

70     public void setName(String JavaDoc name) {
71
72     this.name = name;
73
74     }
75
76     /**
77      * Return the password
78      */

79     public String JavaDoc getPassword() {
80
81     return (this.password);
82
83     }
84
85     /**
86      * Set the password
87      *
88      */

89     public void setPassword(String JavaDoc password) {
90
91     this.password = password;
92
93     }
94
95     /**
96      * Return the email
97      */

98     public String JavaDoc getEmail() {
99
100     return (this.email);
101
102     }
103
104     /**
105      * Set the email
106      *
107      */

108     public void setEmail(String JavaDoc email) {
109
110     this.email = email;
111
112     }
113
114     /**
115      * Return the jabber address
116      */

117     public String JavaDoc getJabber() {
118
119     return (this.jabber);
120
121     }
122
123     /**
124      * Set the jabber address
125      *
126      */

127     public void setJabber(String JavaDoc jabber) {
128
129     this.jabber = jabber;
130
131     }
132
133
134     // --------------------------------------------------------- Public Methods
135

136
137     /**
138      * Reset all properties to their default values.
139      *
140      * @param mapping The mapping used to select this instance
141      * @param request The servlet request we are processing
142      */

143     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
144
145         this.name = null;
146         this.password = null;
147         this.email = null;
148         this.jabber = null;
149     }
150
151     /**
152      * Validate the properties that have been set from this HTTP request,
153      * and return an <code>ActionErrors</code> object that encapsulates any
154      * validation errors that have been found. If no errors are found, return
155      * <code>null</code> or an <code>ActionErrors</code> object with no
156      * recorded error messages.
157      *
158      * @param mapping The mapping used to select this instance
159      * @param request The servlet request we are processing
160      */

161     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
162
163         ActionErrors errors = new ActionErrors();
164
165         if (name == null || name.length()==0)
166             errors.add("name",
167                    new ActionError("error.username.required"));
168         if (password == null || password.length()==0)
169         errors.add("password",
170                new ActionError("error.password.required"));
171         if (email == null || email.length()==0)
172         errors.add("email",
173         new ActionError("error.email.required"));
174         if (jabber == null || jabber.length()==0)
175         errors.add("jabber",
176         new ActionError("error.jabber.required"));
177
178     return (errors);
179
180     }
181 }
182
Popular Tags