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