KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * LoginForm.java
3  */

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

25
26
27 public final class LoginForm extends ActionForm {
28     private String JavaDoc userName = null;
29     private String JavaDoc password = null;
30    
31     /**
32      * Get the userName
33      *@return String
34      */

35     public String JavaDoc getUserName() {
36         return (userName);
37     }
38
39     /**
40      * Set the userName.
41      * @param userName
42      */

43     public void setUserName(String JavaDoc newUserName) {
44         userName = newUserName;
45     }
46
47     /**
48      * Get the password
49      *@return String
50      */

51     public String JavaDoc getPassword() {
52         return (password);
53     }
54
55     /**
56      * Set the password.
57      * @param password
58      */

59     public void setPassword(String JavaDoc newPassword) {
60         password = newPassword;
61     }
62
63
64     /**
65      * Reset all properties to their default values.
66      *
67      * @param mapping The mapping used to select this instance
68      * @param request The servlet request we are processing
69      */

70     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
71     userName = null;
72         password = null;
73         
74     }
75
76     /**
77      * Validate the properties that have been set from this HTTP request,
78      * and return an <code>ActionErrors</code> object that encapsulates any
79      * validation errors that have been found. If no errors are found, return
80      * <code>null</code> or an <code>ActionErrors</code> object with no
81      * recorded error messages.
82      *
83      * @param mapping The mapping used to select this instance
84      * @param request The servlet request we are processing
85      */

86     public ActionErrors validate(ActionMapping mapping,
87                                  HttpServletRequest JavaDoc request) {
88         ActionErrors errors = new ActionErrors();
89         if( userName == null || userName.length()==0 ){
90             errors.add("userName",new ActionError("error.userName.required"));
91         }
92
93         if( password == null || password.length()==0 ){
94             errors.add("password",new ActionError("error.password.required"));
95         }
96         return (errors);
97     }
98
99
100
101 }
102
103
Popular Tags