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 | |
|
22 | |
import org.apache.myfaces.shared_impl.taglib.UIComponentELTagUtils; |
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 | |
|
38 | |
public class ConvertNumberTag |
39 | |
extends ConverterTag |
40 | |
{ |
41 | |
private static final long serialVersionUID = -8365745569697171573L; |
42 | 0 | private ValueExpression _currencyCode = null; |
43 | 0 | private ValueExpression _currencySymbol = null; |
44 | 0 | private ValueExpression _groupingUsed = null; |
45 | 0 | private ValueExpression _integerOnly = null; |
46 | 0 | private ValueExpression _locale = null; |
47 | 0 | private ValueExpression _maxFractionDigits = null; |
48 | 0 | private ValueExpression _maxIntegerDigits = null; |
49 | 0 | private ValueExpression _minFractionDigits = null; |
50 | 0 | private ValueExpression _minIntegerDigits = null; |
51 | 0 | private ValueExpression _pattern = null; |
52 | 0 | private ValueExpression _type = null; |
53 | |
|
54 | |
public ConvertNumberTag() |
55 | 0 | { |
56 | 0 | setConverterIdString(NumberConverter.CONVERTER_ID); |
57 | 0 | } |
58 | |
|
59 | |
public void setCurrencyCode(ValueExpression currencyCode) |
60 | |
{ |
61 | 0 | _currencyCode = currencyCode; |
62 | 0 | } |
63 | |
|
64 | |
public void setCurrencySymbol(ValueExpression currencySymbol) |
65 | |
{ |
66 | 0 | _currencySymbol = currencySymbol; |
67 | 0 | } |
68 | |
|
69 | |
public void setGroupingUsed(ValueExpression groupingUsed) |
70 | |
{ |
71 | 0 | _groupingUsed = groupingUsed; |
72 | 0 | } |
73 | |
|
74 | |
public void setIntegerOnly(ValueExpression integerOnly) |
75 | |
{ |
76 | 0 | _integerOnly = integerOnly; |
77 | 0 | } |
78 | |
|
79 | |
public void setLocale(ValueExpression locale) |
80 | |
{ |
81 | 0 | _locale = locale; |
82 | 0 | } |
83 | |
|
84 | |
public void setMaxFractionDigits(ValueExpression maxFractionDigits) |
85 | |
{ |
86 | 0 | _maxFractionDigits = maxFractionDigits; |
87 | 0 | } |
88 | |
|
89 | |
public void setMaxIntegerDigits(ValueExpression maxIntegerDigits) |
90 | |
{ |
91 | 0 | _maxIntegerDigits = maxIntegerDigits; |
92 | 0 | } |
93 | |
|
94 | |
public void setMinFractionDigits(ValueExpression minFractionDigits) |
95 | |
{ |
96 | 0 | _minFractionDigits = minFractionDigits; |
97 | 0 | } |
98 | |
|
99 | |
public void setMinIntegerDigits(ValueExpression minIntegerDigits) |
100 | |
{ |
101 | 0 | _minIntegerDigits = minIntegerDigits; |
102 | 0 | } |
103 | |
|
104 | |
public void setPattern(ValueExpression pattern) |
105 | |
{ |
106 | 0 | _pattern = pattern; |
107 | 0 | } |
108 | |
|
109 | |
public void setType(ValueExpression type) |
110 | |
{ |
111 | 0 | _type = type; |
112 | 0 | } |
113 | |
|
114 | |
public void setPageContext(PageContext context) |
115 | |
{ |
116 | 0 | super.setPageContext(context); |
117 | 0 | setConverterIdString(NumberConverter.CONVERTER_ID); |
118 | 0 | } |
119 | |
|
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( |
127 | |
(String) UIComponentELTagUtils.evaluateValueExpression(elContext, _currencyCode)); |
128 | |
} |
129 | 0 | if (null != _currencySymbol) |
130 | |
{ |
131 | 0 | converter.setCurrencySymbol( |
132 | |
(String) UIComponentELTagUtils.evaluateValueExpression(elContext, _currencySymbol)); |
133 | |
} |
134 | 0 | if (null != _groupingUsed) |
135 | |
{ |
136 | 0 | converter.setGroupingUsed(UIComponentELTagUtils.getBooleanValue(elContext, _groupingUsed)); |
137 | |
} else |
138 | |
{ |
139 | 0 | converter.setGroupingUsed(true); |
140 | |
} |
141 | 0 | if (null != _integerOnly) |
142 | |
{ |
143 | 0 | converter.setIntegerOnly(UIComponentELTagUtils.getBooleanValue(elContext, _integerOnly)); |
144 | |
} else |
145 | |
{ |
146 | 0 | converter.setIntegerOnly(false); |
147 | |
} |
148 | 0 | if (null != _locale) |
149 | |
{ |
150 | |
Locale locale; |
151 | 0 | if (_locale.isLiteralText()) |
152 | |
{ |
153 | 0 | locale = new Locale(_locale.getExpressionString()); |
154 | |
} else |
155 | |
{ |
156 | 0 | locale = (Locale) _locale.getValue(elContext); |
157 | 0 | if (null == locale) |
158 | |
{ |
159 | 0 | locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); |
160 | |
} |
161 | |
} |
162 | 0 | converter.setLocale(locale); |
163 | |
} |
164 | 0 | if (null != _maxFractionDigits) |
165 | |
{ |
166 | 0 | converter.setMaxFractionDigits(UIComponentELTagUtils.getIntegerValue(elContext, _maxFractionDigits)); |
167 | |
} |
168 | 0 | if (null != _maxIntegerDigits) |
169 | |
{ |
170 | 0 | converter.setMaxIntegerDigits(UIComponentELTagUtils.getIntegerValue(elContext, _maxIntegerDigits)); |
171 | |
} |
172 | 0 | if (null != _minFractionDigits) |
173 | |
{ |
174 | 0 | converter.setMinFractionDigits(UIComponentELTagUtils.getIntegerValue(elContext, _minFractionDigits)); |
175 | |
} |
176 | 0 | if (null != _minIntegerDigits) |
177 | |
{ |
178 | 0 | converter.setMinIntegerDigits(UIComponentELTagUtils.getIntegerValue(elContext, _minIntegerDigits)); |
179 | |
} |
180 | 0 | if (null != _pattern) |
181 | |
{ |
182 | 0 | converter.setPattern((String) UIComponentELTagUtils.evaluateValueExpression(elContext, _pattern)); |
183 | |
} |
184 | 0 | if (null != _type) |
185 | |
{ |
186 | 0 | converter.setType((String) UIComponentELTagUtils.evaluateValueExpression(elContext, _type)); |
187 | |
} else |
188 | |
{ |
189 | 0 | converter.setType("number"); |
190 | |
} |
191 | 0 | return converter; |
192 | |
} |
193 | |
} |