KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

44     /**
45      * Get the name
46      *@return String
47      */

48     public String JavaDoc getName() {
49         return (name);
50     }
51
52     /**
53      * Set the name.
54      * @param name
55      */

56     public void setName(String JavaDoc name) {
57         this.name = name;
58     }
59
60     /**
61      * Get the group name
62      *@return String
63      */

64     public String JavaDoc getGroupName() {
65         return (groupName);
66     }
67
68     /**
69      * Set the group name
70      * @param groupName
71      */

72     public void setGroupName(String JavaDoc groupName) {
73         this.groupName = groupName;
74     }
75     
76     // --------------------------------------------------------- Public Methods
77

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

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

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