1
2
3
4
5
6
7
8
9
10
11
12 package fr.hyphonem.conges.forms;
13
14 import java.text.ParseException;
15 import java.text.SimpleDateFormat;
16 import java.util.logging.Logger;
17
18 import javax.servlet.http.HttpServletRequest;
19
20 import org.apache.struts.action.ActionError;
21 import org.apache.struts.action.ActionErrors;
22 import org.apache.struts.action.ActionForm;
23 import org.apache.struts.action.ActionMapping;
24
25
26
27
28
29 public class AbsForm extends ActionForm {
30
31
32
33 private static final long serialVersionUID = 1L;
34
35 private String id;
36
37 private String datedeb;
38
39 private String datefin;
40
41 private String raison;
42
43 private boolean cbmatin;
44
45 private boolean cbaprem;
46
47 private boolean delete;
48
49 private boolean edition;
50
51 private String period;
52
53 private String perioddatefin;
54
55 public String getPerioddatefin() {
56 return perioddatefin;
57 }
58
59 public void setPerioddatefin(String perioddatefin) {
60 this.perioddatefin = perioddatefin;
61 }
62
63
64
65
66 public AbsForm() {
67 super();
68 resetFields();
69 }
70
71
72
73
74
75
76
77
78
79 public void reset(ActionMapping mapping, HttpServletRequest request) {
80 resetFields();
81
82 }
83
84 private void resetFields() {
85 id = "";
86 datedeb = "";
87 datefin = "";
88 raison = "";
89 period = "none";
90 perioddatefin = "";
91 cbmatin = false;
92 cbaprem = false;
93 delete = false;
94 edition = false;
95 }
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 public ActionErrors validate(ActionMapping mapping,
111 HttpServletRequest request) {
112 ActionErrors errors = new ActionErrors();
113
114 if (datedeb == null || datedeb.trim().equals("")) {
115 errors.add("begin.date.required", new ActionError(
116 "begin.date.required"));
117 }
118
119 if (datefin == null || datefin.trim().equals("")) {
120 errors.add("end.date.required",
121 new ActionError("end.date.required"));
122 }
123
124 if (!cbmatin && !cbaprem) {
125 errors.add("one.of.checkbox.required", new ActionError(
126 "one.of.checkbox.required"));
127 }
128
129
130 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
131
132 if (!period.equalsIgnoreCase("none")) {
133 if (perioddatefin == null || perioddatefin.trim().equals("")) {
134 errors.add("error.period.end.date.not.fill", new ActionError(
135 "error.period.end.date.not.fill"));
136 } else if (perioddatefin != null
137 && !perioddatefin.trim().equals("")) {
138 try {
139 sdf.parse(perioddatefin);
140 } catch (ParseException pe) {
141 errors.add("error.date.format", new ActionError(
142 "error.date.format", "perioddatefin"));
143 }
144 }
145 }
146
147 try {
148 if (datedeb != null && !datedeb.trim().equals("")) {
149 sdf.parse(datedeb);
150 }
151 } catch (ParseException pe) {
152 errors.add("error.date.format", new ActionError(
153 "error.date.format", "datedeb"));
154 }
155
156 try {
157 if (datefin != null && !datefin.trim().equals("")) {
158 sdf.parse(datefin);
159 }
160 } catch (ParseException pe) {
161 errors.add("error.date.format", new ActionError(
162 "error.date.format", "datefin"));
163 }
164
165 try {
166 if (datedeb != null && !datedeb.trim().equals("")
167 && datefin != null && !datefin.trim().equals("")
168 && sdf.parse(datedeb).after(sdf.parse(datefin))) {
169 errors.add("error.end.date.before.begin.date", new ActionError(
170 "error.end.date.before.begin.date"));
171 }
172 } catch (ParseException pe) {
173 Logger.getAnonymousLogger().info(pe.getMessage());
174 }
175
176 request.setAttribute("absForm", this);
177 return errors;
178 }
179
180
181
182
183
184
185 public String getDatedeb() {
186 return datedeb;
187 }
188
189
190
191
192
193
194 public String getDatefin() {
195 return datefin;
196 }
197
198
199
200
201
202
203 public String getRaison() {
204 return raison;
205 }
206
207
208
209
210
211
212
213 public void setDatedeb(String datedeb) {
214 this.datedeb = datedeb;
215 }
216
217
218
219
220
221
222
223 public void setDatefin(String datefin) {
224 this.datefin = datefin;
225 }
226
227
228
229
230
231
232
233 public void setRaison(String raison) {
234 this.raison = raison;
235 }
236
237
238
239
240
241
242 public boolean isCbaprem() {
243 return cbaprem;
244 }
245
246
247
248
249
250
251 public boolean isCbmatin() {
252 return cbmatin;
253 }
254
255
256
257
258
259
260
261 public void setCbaprem(boolean cbaprem) {
262 this.cbaprem = cbaprem;
263 }
264
265
266
267
268
269
270
271 public void setCbmatin(boolean cbmatin) {
272 this.cbmatin = cbmatin;
273 }
274
275
276
277
278 public boolean isDelete() {
279 return delete;
280 }
281
282
283
284
285 public void setDelete(boolean b) {
286 delete = b;
287 }
288
289
290
291
292 public boolean isEdition() {
293 return edition;
294 }
295
296
297
298
299 public void setEdition(boolean b) {
300 edition = b;
301 }
302
303 public String getId() {
304 return id;
305 }
306
307 public void setId(String id) {
308 this.id = id;
309 }
310
311 public String getPeriod() {
312 return period;
313 }
314
315 public void setPeriod(String period) {
316 this.period = period;
317 }
318
319 }