1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.apache.shale.validator.tag; |
19 |
|
|
20 |
|
import javax.faces.context.FacesContext; |
21 |
|
import javax.faces.el.ValueBinding; |
22 |
|
import javax.faces.validator.Validator; |
23 |
|
import javax.faces.webapp.UIComponentTag; |
24 |
|
import javax.faces.webapp.ValidatorTag; |
25 |
|
import org.apache.shale.util.ConverterHelper; |
26 |
|
import org.apache.shale.validator.validator.IntegerValidator; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
0 |
public final class IntegerValidatorTag extends ValidatorTag { |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
private static final long serialVersionUID = 1L; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
0 |
private static final ConverterHelper HELPER = |
47 |
|
new ConverterHelper(); |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
0 |
private String client = null; |
54 |
|
public void setClient(String client) { |
55 |
0 |
this.client = client; |
56 |
0 |
} |
57 |
|
|
58 |
|
|
59 |
0 |
private String maximum = null; |
60 |
|
public void setMaximum(String maximum) { |
61 |
0 |
this.maximum = maximum; |
62 |
0 |
} |
63 |
|
|
64 |
|
|
65 |
0 |
private String message = null; |
66 |
|
public void setMessage(String message) { |
67 |
0 |
this.message = message; |
68 |
0 |
} |
69 |
|
|
70 |
|
|
71 |
0 |
private String minimum = null; |
72 |
|
public void setMinimum(String minimum) { |
73 |
0 |
this.minimum = minimum; |
74 |
0 |
} |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
public void release() { |
84 |
|
|
85 |
0 |
client = null; |
86 |
0 |
maximum = null; |
87 |
0 |
message = null; |
88 |
0 |
minimum = null; |
89 |
|
|
90 |
0 |
super.release(); |
91 |
|
|
92 |
0 |
} |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
protected Validator createValidator() { |
103 |
|
|
104 |
0 |
FacesContext context = FacesContext.getCurrentInstance(); |
105 |
0 |
IntegerValidator validator = new IntegerValidator(); |
106 |
|
|
107 |
0 |
if (client != null) { |
108 |
0 |
Boolean value = null; |
109 |
0 |
if (UIComponentTag.isValueReference(client)) { |
110 |
0 |
ValueBinding vb = context.getApplication().createValueBinding(client); |
111 |
0 |
value = (Boolean) vb.getValue(context); |
112 |
0 |
} else { |
113 |
0 |
value = (Boolean) HELPER.asObject(context, Boolean.class, client); |
114 |
|
} |
115 |
0 |
validator.setClient(value.booleanValue()); |
116 |
|
} |
117 |
|
|
118 |
0 |
if (maximum != null) { |
119 |
0 |
Integer value = null; |
120 |
0 |
if (UIComponentTag.isValueReference(maximum)) { |
121 |
0 |
ValueBinding vb = context.getApplication().createValueBinding(maximum); |
122 |
0 |
value = (Integer) vb.getValue(context); |
123 |
0 |
} else { |
124 |
0 |
value = (Integer) HELPER.asObject(context, Integer.class, maximum); |
125 |
|
} |
126 |
0 |
validator.setMaximum(value.intValue()); |
127 |
|
} |
128 |
|
|
129 |
0 |
if (message != null) { |
130 |
0 |
String value = null; |
131 |
0 |
if (UIComponentTag.isValueReference(message)) { |
132 |
0 |
ValueBinding vb = context.getApplication().createValueBinding(message); |
133 |
0 |
value = (String) vb.getValue(context); |
134 |
0 |
} else { |
135 |
0 |
value = message; |
136 |
|
} |
137 |
0 |
validator.setMessage(value); |
138 |
|
} |
139 |
|
|
140 |
0 |
if (minimum != null) { |
141 |
0 |
Integer value = null; |
142 |
0 |
if (UIComponentTag.isValueReference(minimum)) { |
143 |
0 |
ValueBinding vb = context.getApplication().createValueBinding(minimum); |
144 |
0 |
value = (Integer) vb.getValue(context); |
145 |
0 |
} else { |
146 |
0 |
value = (Integer) HELPER.asObject(context, Integer.class, minimum); |
147 |
|
} |
148 |
0 |
validator.setMinimum(value.intValue()); |
149 |
|
} |
150 |
|
|
151 |
0 |
return validator; |
152 |
|
|
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
} |