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 private String _converterIdString = null;
41
42 public ConverterTag()
43 {
44 super();
45 }
46
47 public void setConverterId(ValueExpression converterId)
48 {
49 _converterId = converterId;
50 }
51
52 public void setBinding(ValueExpression binding)
53 {
54 _binding = binding;
55 }
56
57
58
59
60
61
62 public void setConverterIdString(String converterIdString)
63 {
64 _converterIdString = converterIdString;
65 }
66
67 public void release()
68 {
69 super.release();
70 _converterId = null;
71 _binding = null;
72 _converterIdString = null;
73 }
74
75 protected Converter createConverter()
76 throws JspException
77 {
78 Converter converter = null;
79
80 FacesContext facesContext = FacesContext.getCurrentInstance();
81 ELContext elContext = facesContext.getELContext();
82
83
84
85 if (_binding != null)
86 {
87 try
88 {
89 converter = (Converter) _binding.getValue(elContext);
90
91 if (converter != null)
92 {
93 return converter;
94 }
95 }
96 catch (Exception e)
97 {
98 throw new JspException("Exception creating converter using binding", e);
99 }
100 }
101
102 if ((_converterId != null) || (_converterIdString != null))
103 {
104 try
105 {
106 if (null != _converterIdString)
107 {
108 converter = facesContext.getApplication().createConverter(_converterIdString);
109 } else
110 {
111 String converterId = (String) _converterId.getValue(elContext);
112 converter = facesContext.getApplication().createConverter(converterId);
113 }
114
115
116
117 if (converter != null && _binding != null)
118 {
119 _binding.setValue(elContext, converter);
120 }
121 }
122 catch (Exception e)
123 {
124 throw new JspException("Exception creating converter with converterId: " + _converterId, e);
125 }
126 }
127
128 return converter;
129 }
130
131 }