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 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public class ConverterTag extends ConverterELTag |
35 | |
{ |
36 | |
|
37 | |
private static final long serialVersionUID = -4506829108081L; |
38 | |
private ValueExpression _converterId; |
39 | |
private ValueExpression _binding; |
40 | 0 | private String _converterIdString = null; |
41 | |
|
42 | |
public ConverterTag() |
43 | |
{ |
44 | 0 | super(); |
45 | 0 | } |
46 | |
|
47 | |
public void setConverterId(ValueExpression converterId) |
48 | |
{ |
49 | 0 | _converterId = converterId; |
50 | 0 | } |
51 | |
|
52 | |
public void setBinding(ValueExpression binding) |
53 | |
{ |
54 | 0 | _binding = binding; |
55 | 0 | } |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public void setConverterIdString(String converterIdString) |
63 | |
{ |
64 | 0 | _converterIdString = converterIdString; |
65 | 0 | } |
66 | |
|
67 | |
@Override |
68 | |
public void release() |
69 | |
{ |
70 | 0 | super.release(); |
71 | 0 | _converterId = null; |
72 | 0 | _binding = null; |
73 | 0 | _converterIdString = null; |
74 | 0 | } |
75 | |
|
76 | |
@Override |
77 | |
protected Converter createConverter() throws JspException |
78 | |
{ |
79 | 0 | Converter converter = null; |
80 | |
|
81 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
82 | 0 | ELContext elContext = facesContext.getELContext(); |
83 | |
|
84 | |
|
85 | |
|
86 | 0 | if (_binding != null) |
87 | |
{ |
88 | |
try |
89 | |
{ |
90 | 0 | converter = (Converter)_binding.getValue(elContext); |
91 | |
|
92 | 0 | if (converter != null) |
93 | |
{ |
94 | 0 | return converter; |
95 | |
} |
96 | |
} |
97 | 0 | catch (Exception e) |
98 | |
{ |
99 | 0 | throw new JspException("Exception creating converter using binding", e); |
100 | 0 | } |
101 | |
} |
102 | |
|
103 | 0 | if ((_converterId != null) || (_converterIdString != null)) |
104 | |
{ |
105 | |
try |
106 | |
{ |
107 | 0 | if (null != _converterIdString) |
108 | |
{ |
109 | 0 | converter = facesContext.getApplication().createConverter(_converterIdString); |
110 | |
} |
111 | |
else |
112 | |
{ |
113 | 0 | String converterId = (String)_converterId.getValue(elContext); |
114 | 0 | converter = facesContext.getApplication().createConverter(converterId); |
115 | |
} |
116 | |
|
117 | |
|
118 | |
|
119 | 0 | if (converter != null && _binding != null) |
120 | |
{ |
121 | 0 | _binding.setValue(elContext, converter); |
122 | |
} |
123 | |
} |
124 | 0 | catch (Exception e) |
125 | |
{ |
126 | 0 | throw new JspException("Exception creating converter with converterId: " + _converterId, e); |
127 | 0 | } |
128 | |
} |
129 | |
|
130 | 0 | if (converter == null) |
131 | |
{ |
132 | 0 | throw new JspException("Could not create converter. Please specify a valid converterId" + |
133 | |
" or a non-null binding."); |
134 | |
} |
135 | |
|
136 | 0 | return converter; |
137 | |
} |
138 | |
|
139 | |
} |