2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
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.FloatValidator;
27
28 /***
29 * <p>JSP custom action for <code>FloatValidator</code>.</p>
30 */
31 public final class FloatValidatorTag extends ValidatorTag {
32
33
34
35
36
37 /***
38 * Serial version UID.
39 */
40 private static final long serialVersionUID = 1L;
41
42
43 /***
44 * <p>Helper object for performing conversions.</p>
45 */
46 private static final ConverterHelper HELPER =
47 new ConverterHelper();
48
49
50
51
52
53 private String client = null;
54 public void setClient(String client) {
55 this.client = client;
56 }
57
58
59 private String maximum = null;
60 public void setMaximum(String maximum) {
61 this.maximum = maximum;
62 }
63
64
65 private String message = null;
66 public void setMessage(String message) {
67 this.message = message;
68 }
69
70
71 private String minimum = null;
72 public void setMinimum(String minimum) {
73 this.minimum = minimum;
74 }
75
76
77
78
79
80 /***
81 * <p>Release resources allocated for this instance.</p>
82 */
83 public void release() {
84
85 client = null;
86 maximum = null;
87 message = null;
88 minimum = null;
89
90 super.release();
91
92 }
93
94
95
96
97
98 /***
99 * <p>Create and return a new <code>Validator</code> instance to be
100 * registered on our corresponding <code>UIComponent</code>.</p>
101 */
102 protected Validator createValidator() {
103
104 FacesContext context = FacesContext.getCurrentInstance();
105 FloatValidator validator = new FloatValidator();
106
107 if (client != null) {
108 Boolean value = null;
109 if (UIComponentTag.isValueReference(client)) {
110 ValueBinding vb = context.getApplication().createValueBinding(client);
111 value = (Boolean) vb.getValue(context);
112 } else {
113 value = (Boolean) HELPER.asObject(context, Boolean.class, client);
114 }
115 validator.setClient(value.booleanValue());
116 }
117
118 if (maximum != null) {
119 Float value = null;
120 if (UIComponentTag.isValueReference(maximum)) {
121 ValueBinding vb = context.getApplication().createValueBinding(maximum);
122 value = (Float) vb.getValue(context);
123 } else {
124 value = (Float) HELPER.asObject(context, Float.class, maximum);
125 }
126 validator.setMaximum(value.floatValue());
127 }
128
129 if (message != null) {
130 String value = null;
131 if (UIComponentTag.isValueReference(message)) {
132 ValueBinding vb = context.getApplication().createValueBinding(message);
133 value = (String) vb.getValue(context);
134 } else {
135 value = message;
136 }
137 validator.setMessage(value);
138 }
139
140 if (minimum != null) {
141 Float value = null;
142 if (UIComponentTag.isValueReference(minimum)) {
143 ValueBinding vb = context.getApplication().createValueBinding(minimum);
144 value = (Float) vb.getValue(context);
145 } else {
146 value = (Float) HELPER.asObject(context, Float.class, minimum);
147 }
148 validator.setMinimum(value.floatValue());
149 }
150
151 return validator;
152
153 }
154
155
156 }