1
2
3
4
5
6
7
8
9
10
11
12 package fr.hyphonem.conges.forms;
13
14 import javax.servlet.http.HttpServletRequest;
15
16 import org.apache.regexp.RE;
17 import org.apache.struts.action.ActionError;
18 import org.apache.struts.action.ActionErrors;
19 import org.apache.struts.action.ActionForm;
20 import org.apache.struts.action.ActionMapping;
21
22
23
24
25
26 public class ValidPeriodParamForm extends ActionForm {
27
28
29
30
31 private static final long serialVersionUID = 4403846273476714068L;
32
33 private String code;
34
35 private String label;
36
37
38
39
40 public ValidPeriodParamForm() {
41 super();
42 resetFields();
43 }
44
45
46
47
48
49
50
51
52
53 public void reset(ActionMapping mapping, HttpServletRequest request) {
54 resetFields();
55
56 }
57
58 private void resetFields() {
59 code = "";
60 label = "";
61 }
62
63 public ActionErrors validate(ActionMapping mapping,
64 HttpServletRequest request) {
65 ActionErrors errors = new ActionErrors();
66 if (code == null || code.trim().equals("")) {
67 errors.add("error.code.required", new ActionError(
68 "error.code.required"));
69 }
70 if (label == null || label.trim().equals("")) {
71 errors.add("error.label.required", new ActionError(
72 "error.label.required"));
73 }
74
75 RE regexp = new RE("^[0-9]*$");
76
77 if (!regexp.match(code)) {
78 errors.add("error.num.format", new ActionError("error.num.format",
79 "code"));
80 } else if (code != null && !code.trim().equals("")
81 && new Integer(code).intValue() > 182) {
82 errors.add("error.max.period", new ActionError("error.max.period",
83 "code"));
84 }
85 return errors;
86 }
87
88 public String getCode() {
89 return code;
90 }
91
92 public void setCode(String code) {
93 this.code = code;
94 }
95
96 public String getLabel() {
97 return label;
98 }
99
100 public void setLabel(String label) {
101 this.label = label;
102 }
103
104 }