1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.taglib.core; |
20 | |
|
21 | |
import org.apache.myfaces.shared.taglib.UIComponentELTagUtils; |
22 | |
import org.apache.myfaces.shared.util.LocaleUtils; |
23 | |
|
24 | |
import javax.el.ELContext; |
25 | |
import javax.el.ValueExpression; |
26 | |
import javax.faces.context.FacesContext; |
27 | |
import javax.faces.convert.Converter; |
28 | |
import javax.faces.convert.NumberConverter; |
29 | |
import javax.servlet.jsp.JspException; |
30 | |
import javax.servlet.jsp.PageContext; |
31 | |
import java.util.Locale; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class ConvertNumberTag extends ConverterTag |
38 | |
{ |
39 | |
private static final long serialVersionUID = -8365745569697171573L; |
40 | 0 | private ValueExpression _currencyCode = null; |
41 | 0 | private ValueExpression _currencySymbol = null; |
42 | 0 | private ValueExpression _groupingUsed = null; |
43 | 0 | private ValueExpression _integerOnly = null; |
44 | 0 | private ValueExpression _locale = null; |
45 | 0 | private ValueExpression _maxFractionDigits = null; |
46 | 0 | private ValueExpression _maxIntegerDigits = null; |
47 | 0 | private ValueExpression _minFractionDigits = null; |
48 | 0 | private ValueExpression _minIntegerDigits = null; |
49 | 0 | private ValueExpression _pattern = null; |
50 | 0 | private ValueExpression _type = null; |
51 | |
|
52 | |
public ConvertNumberTag() |
53 | 0 | { |
54 | 0 | setConverterIdString(NumberConverter.CONVERTER_ID); |
55 | 0 | } |
56 | |
|
57 | |
public void setCurrencyCode(ValueExpression currencyCode) |
58 | |
{ |
59 | 0 | _currencyCode = currencyCode; |
60 | 0 | } |
61 | |
|
62 | |
public void setCurrencySymbol(ValueExpression currencySymbol) |
63 | |
{ |
64 | 0 | _currencySymbol = currencySymbol; |
65 | 0 | } |
66 | |
|
67 | |
public void setGroupingUsed(ValueExpression groupingUsed) |
68 | |
{ |
69 | 0 | _groupingUsed = groupingUsed; |
70 | 0 | } |
71 | |
|
72 | |
public void setIntegerOnly(ValueExpression integerOnly) |
73 | |
{ |
74 | 0 | _integerOnly = integerOnly; |
75 | 0 | } |
76 | |
|
77 | |
public void setLocale(ValueExpression locale) |
78 | |
{ |
79 | 0 | _locale = locale; |
80 | 0 | } |
81 | |
|
82 | |
public void setMaxFractionDigits(ValueExpression maxFractionDigits) |
83 | |
{ |
84 | 0 | _maxFractionDigits = maxFractionDigits; |
85 | 0 | } |
86 | |
|
87 | |
public void setMaxIntegerDigits(ValueExpression maxIntegerDigits) |
88 | |
{ |
89 | 0 | _maxIntegerDigits = maxIntegerDigits; |
90 | 0 | } |
91 | |
|
92 | |
public void setMinFractionDigits(ValueExpression minFractionDigits) |
93 | |
{ |
94 | 0 | _minFractionDigits = minFractionDigits; |
95 | 0 | } |
96 | |
|
97 | |
public void setMinIntegerDigits(ValueExpression minIntegerDigits) |
98 | |
{ |
99 | 0 | _minIntegerDigits = minIntegerDigits; |
100 | 0 | } |
101 | |
|
102 | |
public void setPattern(ValueExpression pattern) |
103 | |
{ |
104 | 0 | _pattern = pattern; |
105 | 0 | } |
106 | |
|
107 | |
public void setType(ValueExpression type) |
108 | |
{ |
109 | 0 | _type = type; |
110 | 0 | } |
111 | |
|
112 | |
@Override |
113 | |
public void setPageContext(PageContext context) |
114 | |
{ |
115 | 0 | super.setPageContext(context); |
116 | 0 | setConverterIdString(NumberConverter.CONVERTER_ID); |
117 | 0 | } |
118 | |
|
119 | |
@Override |
120 | |
protected Converter createConverter() throws JspException |
121 | |
{ |
122 | 0 | NumberConverter converter = (NumberConverter)super.createConverter(); |
123 | 0 | ELContext elContext = FacesContext.getCurrentInstance().getELContext(); |
124 | 0 | if (null != _currencyCode) |
125 | |
{ |
126 | 0 | converter.setCurrencyCode((String)UIComponentELTagUtils.evaluateValueExpression(elContext, _currencyCode)); |
127 | |
} |
128 | 0 | if (null != _currencySymbol) |
129 | |
{ |
130 | 0 | converter.setCurrencySymbol((String)UIComponentELTagUtils.evaluateValueExpression(elContext, |
131 | |
_currencySymbol)); |
132 | |
} |
133 | 0 | if (null != _groupingUsed) |
134 | |
{ |
135 | 0 | converter.setGroupingUsed(UIComponentELTagUtils.getBooleanValue(elContext, _groupingUsed)); |
136 | |
} |
137 | |
else |
138 | |
{ |
139 | 0 | converter.setGroupingUsed(true); |
140 | |
} |
141 | 0 | if (null != _integerOnly) |
142 | |
{ |
143 | 0 | converter.setIntegerOnly(UIComponentELTagUtils.getBooleanValue(elContext, _integerOnly)); |
144 | |
} |
145 | |
else |
146 | |
{ |
147 | 0 | converter.setIntegerOnly(false); |
148 | |
} |
149 | 0 | if (null != _locale) |
150 | |
{ |
151 | |
Locale locale; |
152 | 0 | if (_locale.isLiteralText()) |
153 | |
{ |
154 | 0 | locale = LocaleUtils.toLocale(_locale.getExpressionString()); |
155 | |
} |
156 | |
else |
157 | |
{ |
158 | 0 | Object localeValue = _locale.getValue(elContext); |
159 | 0 | if (localeValue instanceof Locale) |
160 | |
{ |
161 | 0 | locale = (Locale)localeValue; |
162 | |
} |
163 | |
else |
164 | |
{ |
165 | 0 | locale = LocaleUtils.toLocale(localeValue.toString()); |
166 | |
} |
167 | 0 | if (null == locale) |
168 | |
{ |
169 | 0 | locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); |
170 | |
} |
171 | |
} |
172 | 0 | converter.setLocale(locale); |
173 | |
} |
174 | 0 | if (null != _maxFractionDigits) |
175 | |
{ |
176 | 0 | converter.setMaxFractionDigits(UIComponentELTagUtils.getIntegerValue(elContext, _maxFractionDigits)); |
177 | |
} |
178 | 0 | if (null != _maxIntegerDigits) |
179 | |
{ |
180 | 0 | converter.setMaxIntegerDigits(UIComponentELTagUtils.getIntegerValue(elContext, _maxIntegerDigits)); |
181 | |
} |
182 | 0 | if (null != _minFractionDigits) |
183 | |
{ |
184 | 0 | converter.setMinFractionDigits(UIComponentELTagUtils.getIntegerValue(elContext, _minFractionDigits)); |
185 | |
} |
186 | 0 | if (null != _minIntegerDigits) |
187 | |
{ |
188 | 0 | converter.setMinIntegerDigits(UIComponentELTagUtils.getIntegerValue(elContext, _minIntegerDigits)); |
189 | |
} |
190 | 0 | if (null != _pattern) |
191 | |
{ |
192 | 0 | converter.setPattern((String)UIComponentELTagUtils.evaluateValueExpression(elContext, _pattern)); |
193 | |
} |
194 | 0 | if (null != _type) |
195 | |
{ |
196 | 0 | converter.setType((String)UIComponentELTagUtils.evaluateValueExpression(elContext, _type)); |
197 | |
} |
198 | |
else |
199 | |
{ |
200 | 0 | converter.setType("number"); |
201 | |
} |
202 | 0 | return converter; |
203 | |
} |
204 | |
} |