KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * UserRoleForm.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 node. This form has the following fields,
16  * with default values in square brackets:
17  * <ul>
18  * <li><b>user</b> - The username. [REQUIRED]
19  * <li><b>role</b> - The user role. [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 UserRoleForm extends ActionForm {
28     
29     // --------------------------------------------------- Instance Variables
30

31     /**
32      * The name of the user
33      */

34     private String JavaDoc user = null;
35
36     /**
37      * The role of the user
38      */

39     private String JavaDoc role = null;
40
41
42     
43     // ----------------------------------------------------------- Properties
44

45     /**
46      * Get the user
47      *@return String
48      */

49     public String JavaDoc getUser() {
50         return (user);
51     }
52
53     /**
54      * Set the user
55      * @param user
56      */

57     public void setUser(String JavaDoc user) {
58         this.user = user;
59     }
60
61     /**
62      * Get the role
63      *@return String
64      */

65     public String JavaDoc getRole() {
66         return (role);
67     }
68
69     /**
70      * Set the role
71      * @param role
72      */

73     public void setRole(String JavaDoc role) {
74         this.role = role;
75     }
76
77
78     // --------------------------------------------------------- Public Methods
79

80     /**
81      * Reset all properties to their default values.
82      *
83      * @param mapping The mapping used to select this instance
84      * @param request The servlet request we are processing
85      */

86     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
87     this.user = null;
88     this.role = null;
89     }
90
91
92     /**
93      * Validate the properties that have been set from this HTTP request,
94      * and return an <code>ActionErrors</code> object that encapsulates any
95      * validation errors that have been found. If no errors are found, return
96      * <code>null</code> or an <code>ActionErrors</code> object with no
97      * recorded error messages.
98      *
99      * @param mapping The mapping used to select this instance
100      * @param request The servlet request we are processing
101      */

102     public ActionErrors validate(ActionMapping mapping,
103                                  HttpServletRequest JavaDoc request) {
104         ActionErrors errors = new ActionErrors();
105         if (user == null || user.length()==0)
106             errors.add("user",
107                    new ActionError("error.user.required"));
108         if (role == null || role.length()==0)
109             errors.add("role",
110                    new ActionError("error.role.required"));
111
112         return (errors);
113     }
114
115
116
117 }
118
119
Popular Tags