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