1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.webapp.example2;
19
20
21 import javax.servlet.http.HttpServletRequest;
22 import org.apache.struts.action.ActionMessage;
23 import org.apache.struts.action.ActionErrors;
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.action.ActionMapping;
26
27
28 /***
29 * Form bean for the user profile page. 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 Craig R. McClanahan
37 * @version $Rev: 421494 $ $Date: 2006-07-12 20:55:17 -0700 (Wed, 12 Jul 2006) $
38 */
39
40 public final class LogonForm extends ActionForm {
41
42
43
44
45
46 /***
47 * The password.
48 */
49 private String password = null;
50
51
52 /***
53 * The username.
54 */
55 private String username = null;
56
57
58
59
60
61 /***
62 * Return the password.
63 */
64 public String getPassword() {
65
66 return (this.password);
67
68 }
69
70
71 /***
72 * Set the password.
73 *
74 * @param password The new password
75 */
76 public void setPassword(String password) {
77
78 this.password = password;
79
80 }
81
82
83 /***
84 * Return the username.
85 */
86 public String getUsername() {
87
88 return (this.username);
89
90 }
91
92
93 /***
94 * Set the username.
95 *
96 * @param username The new username
97 */
98 public void setUsername(String username) {
99
100 this.username = username;
101
102 }
103
104
105
106
107
108 /***
109 * Reset all properties to their default values.
110 *
111 * @param mapping The mapping used to select this instance
112 * @param request The servlet request we are processing
113 */
114 public void reset(ActionMapping mapping, HttpServletRequest request) {
115
116 this.password = null;
117 this.username = null;
118
119 }
120
121
122 /***
123 * Validate the properties that have been set from this HTTP request,
124 * and return an <code>ActionErrors</code> object that encapsulates any
125 * validation errors that have been found. If no errors are found, return
126 * <code>null</code> or an <code>ActionErrors</code> object with no
127 * recorded error messages.
128 *
129 * @param mapping The mapping used to select this instance
130 * @param request The servlet request we are processing
131 */
132 public ActionErrors validate(ActionMapping mapping,
133 HttpServletRequest request) {
134
135 ActionErrors errors = new ActionErrors();
136 if ((username == null) || (username.length() < 1))
137 errors.add("username", new ActionMessage("error.username.required"));
138 if ((password == null) || (password.length() < 1))
139 errors.add("password", new ActionMessage("error.password.required"));
140
141 return errors;
142
143 }
144
145
146 }