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