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 java.util.Locale;
21
22 import javax.faces.context.FacesContext;
23 import javax.faces.convert.Converter;
24 import javax.faces.el.ValueBinding;
25 import javax.faces.webapp.ConverterTag;
26 import javax.faces.webapp.UIComponentTag;
27
28 import org.apache.shale.util.ConverterHelper;
29 import org.apache.shale.validator.converter.FloatConverter;
30
31 /***
32 * <p>JSP custom action for <code>FloatConverter</code>.</p>
33 */
34 public final class FloatConverterTag extends ConverterTag {
35
36
37
38
39
40 /***
41 * Serial version UID.
42 */
43 private static final long serialVersionUID = 1L;
44
45
46 /***
47 * <p>Helper object for performing conversions.</p>
48 */
49 private static final ConverterHelper HELPER =
50 new ConverterHelper();
51
52
53
54
55
56 private String locale = null;
57 public void setLocale(String locale) {
58 this.locale = locale;
59 }
60
61
62 private String message = null;
63 public void setMessage(String message) {
64 this.message = message;
65 }
66
67
68 private String pattern = null;
69 public void setPattern(String pattern) {
70 this.pattern = pattern;
71 }
72
73
74
75
76
77 /***
78 * <p>Release resources allocated for this instance.</p>
79 */
80 public void release() {
81
82 locale = null;
83 message = null;
84 pattern = null;
85
86 super.release();
87
88 }
89
90
91
92
93
94 /***
95 * <p>Create and return a new <code>Converter</code> instance to be
96 * registered on our corresponding <code>UIComponent</code>.</p>
97 */
98 protected Converter createConverter() {
99
100 FacesContext context = FacesContext.getCurrentInstance();
101 FloatConverter converter = new FloatConverter();
102
103 if (locale != null) {
104 Locale value = null;
105 if (UIComponentTag.isValueReference(locale)) {
106 ValueBinding vb = context.getApplication().createValueBinding(locale);
107 value = (Locale) vb.getValue(context);
108 } else {
109 value = (Locale) HELPER.asObject(context, Locale.class, locale);
110 }
111 converter.setLocale(value);
112 }
113
114 if (pattern != null) {
115 String value = null;
116 if (UIComponentTag.isValueReference(message)) {
117 ValueBinding vb = context.getApplication().createValueBinding(pattern);
118 value = (String) vb.getValue(context);
119 } else {
120 value = pattern;
121 }
122 converter.setPattern(value);
123 }
124
125 return converter;
126
127 }
128
129
130 }