KickJava   Java API By Example, From Geeks To Geeks.

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


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

24
25 public final class ActivityForm extends ActionForm {
26
27
28 // =================================================== Instance Variables
29

30
31     /**
32      * The activity role
33      */

34     private String JavaDoc role = null;
35
36
37     /**
38      * The activity deadline
39      */

40
41     private String JavaDoc deadline = null;
42
43     /**
44      * The activity description
45      */

46
47          private String JavaDoc description = null;
48
49     /**
50      * Type atribute
51      */

52
53          private String JavaDoc type = null;
54
55     /**
56      * Anticipable atribute
57      */

58
59          private String JavaDoc anticipable = null;
60
61     /**
62      * Automatic atribute
63      */

64
65          private String JavaDoc automatic = null;
66
67     // =========================================================== Properties
68

69
70     /**
71      * Return the activity role
72      */

73     public String JavaDoc getRole() {
74
75     return (this.role);
76
77     }
78
79     /**
80      * Set the activity role
81      *
82      */

83     public void setRole(String JavaDoc role) {
84
85     this.role = role;
86
87     }
88
89     /**
90      * Return the activity deadline
91      */

92     public String JavaDoc getDeadline() {
93         if(this.deadline.length()>10)
94             return (this.deadline.substring(0,10));
95         else
96             return (this.deadline);
97
98     }
99
100     /**
101      * Set the activity deadline
102      *
103      */

104     public void setDeadline(String JavaDoc deadline) {
105
106     this.deadline =deadline;
107
108     }
109
110     /**
111      * Return the activity description
112      */

113     public String JavaDoc getDescription() {
114
115     return (this.description);
116
117     }
118
119     /**
120      * Set the activity description
121      *
122      */

123     public void setDescription (String JavaDoc description) {
124
125     this.description = description;
126
127     }
128
129     /**
130      * Return the activity type
131      */

132     public String JavaDoc getType() {
133
134     return (this.type);
135
136     }
137
138     /**
139      * Set the activity type
140      *
141      */

142     public void setType (String JavaDoc type) {
143     this.type = type;
144     }
145
146     /**
147      * Return the anticipable value
148      */

149     public String JavaDoc getAnticipable() {
150
151     return (this.anticipable);
152
153     }
154
155     /**
156      * Set anticipable value
157      *
158      */

159     public void setAnticipable (String JavaDoc anticipable) {
160
161     this.anticipable = anticipable;
162
163     }
164
165     /**
166      * Return the automatic value
167      */

168     public String JavaDoc getAutomatic() {
169
170     return (this.automatic);
171
172     }
173
174     /**
175      * Set automatic value
176      *
177      */

178     public void setAutomatic (String JavaDoc automatic) {
179
180     this.automatic = automatic;
181
182     }
183
184     // --------------------------------------------------------- Public Methods
185

186
187     /**
188      * Reset all properties to their default values.
189      *
190      * @param mapping The mapping used to select this instance
191      * @param request The servlet request we are processing
192      */

193     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
194
195         this.role = null;
196         this.deadline = null;
197         this.description = null;
198         this.type = null;
199     }
200
201     /**
202      * Validate the properties that have been set from this HTTP request,
203      * and return an <code>ActionErrors</code> object that encapsulates any
204      * validation errors that have been found. If no errors are found, return
205      * <code>null</code> or an <code>ActionErrors</code> object with no
206      * recorded error messages.
207      *
208      * @param mapping The mapping used to select this instance
209      * @param request The servlet request we are processing
210      */

211     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
212
213         ActionErrors errors = new ActionErrors();
214
215         if (role == null || role.length()==0)
216             errors.add("role",
217                    new ActionError("error.role.required"));
218         if (deadline == null || deadline.length()==0)
219         errors.add("deadline",
220                new ActionError("error.deadline.required"));
221         if (description == null || description.length()==0)
222         errors.add("description",
223         new ActionError("error.description.required"));
224
225     return (errors);
226
227     }
228 }
229
Popular Tags