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 javax.el.ELContext; |
22 | |
import javax.el.ValueExpression; |
23 | |
import javax.faces.context.FacesContext; |
24 | |
import javax.faces.convert.Converter; |
25 | |
import javax.faces.webapp.ConverterELTag; |
26 | |
import javax.servlet.jsp.JspException; |
27 | |
|
28 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspAttribute; |
29 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspTag; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
@JSFJspTag( |
40 | |
name="f:converter", |
41 | |
bodyContent="empty") |
42 | |
public class ConverterImplTag extends ConverterELTag |
43 | |
{ |
44 | |
|
45 | |
private static final long serialVersionUID = -4506829108081L; |
46 | |
private ValueExpression _converterId; |
47 | |
private ValueExpression _binding; |
48 | 0 | private String _converterIdString = null; |
49 | |
|
50 | |
public ConverterImplTag() |
51 | |
{ |
52 | 0 | super(); |
53 | 0 | } |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
@JSFJspAttribute( |
59 | |
rtexprvalue=true, |
60 | |
className="java.lang.String") |
61 | |
public void setConverterId(ValueExpression converterId) |
62 | |
{ |
63 | 0 | _converterId = converterId; |
64 | 0 | } |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
@JSFJspAttribute( |
70 | |
rtexprvalue=true, |
71 | |
className="javax.faces.convert.Converter") |
72 | |
public void setBinding(ValueExpression binding) |
73 | |
{ |
74 | 0 | _binding = binding; |
75 | 0 | } |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public void setConverterIdString(String converterIdString) |
83 | |
{ |
84 | 0 | _converterIdString = converterIdString; |
85 | 0 | } |
86 | |
|
87 | |
public void release() |
88 | |
{ |
89 | 0 | super.release(); |
90 | 0 | _converterId = null; |
91 | 0 | _binding = null; |
92 | 0 | _converterIdString = null; |
93 | 0 | } |
94 | |
|
95 | |
protected Converter createConverter() throws JspException |
96 | |
{ |
97 | 0 | if (_converterId != null && _converterId.isLiteralText()) |
98 | |
{ |
99 | 0 | return this.createClassicConverter(); |
100 | |
} |
101 | 0 | if (_converterIdString != null){ |
102 | 0 | return this.createClassicConverter(); |
103 | |
} |
104 | |
|
105 | 0 | return new DelegateConverter(_converterId, _binding, |
106 | |
_converterIdString); |
107 | |
} |
108 | |
|
109 | |
protected Converter createClassicConverter() throws JspException |
110 | |
{ |
111 | 0 | Converter converter = null; |
112 | |
|
113 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
114 | 0 | ELContext elContext = facesContext.getELContext(); |
115 | |
|
116 | |
|
117 | |
|
118 | 0 | if (_binding != null) |
119 | |
{ |
120 | |
try |
121 | |
{ |
122 | 0 | converter = (Converter) _binding.getValue(elContext); |
123 | |
|
124 | 0 | if (converter != null) |
125 | |
{ |
126 | 0 | return converter; |
127 | |
} |
128 | |
} |
129 | 0 | catch (Exception e) |
130 | |
{ |
131 | 0 | throw new JspException( |
132 | |
"Exception creating converter using binding", e); |
133 | 0 | } |
134 | |
} |
135 | |
|
136 | 0 | if ((_converterId != null) || (_converterIdString != null)) |
137 | |
{ |
138 | |
try |
139 | |
{ |
140 | 0 | if (null != _converterIdString) |
141 | |
{ |
142 | 0 | converter = facesContext.getApplication().createConverter( |
143 | |
_converterIdString); |
144 | |
} |
145 | |
else |
146 | |
{ |
147 | 0 | String converterId = (String) _converterId |
148 | |
.getValue(elContext); |
149 | 0 | converter = facesContext.getApplication().createConverter( |
150 | |
converterId); |
151 | |
} |
152 | |
|
153 | |
|
154 | |
|
155 | 0 | if (converter != null && _binding != null) |
156 | |
{ |
157 | 0 | _binding.setValue(elContext, converter); |
158 | |
} |
159 | |
} |
160 | 0 | catch (Exception e) |
161 | |
{ |
162 | 0 | throw new JspException( |
163 | |
"Exception creating converter with converterId: " |
164 | |
+ _converterId, e); |
165 | 0 | } |
166 | |
} |
167 | |
|
168 | 0 | return converter; |
169 | |
} |
170 | |
} |