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