1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.converter;
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
35
36
37
38
39 public class ConverterTag 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 ConverterTag()
48 {
49 super();
50 }
51
52 public void setConverterId(ValueExpression converterId)
53 {
54 _converterId = converterId;
55 }
56
57 public void setBinding(ValueExpression binding)
58 {
59 _binding = binding;
60 }
61
62
63
64
65
66
67 public void setConverterIdString(String converterIdString)
68 {
69 _converterIdString = converterIdString;
70 }
71
72 public void release()
73 {
74 super.release();
75 _converterId = null;
76 _binding = null;
77 _converterIdString = null;
78 }
79
80 protected Converter createConverter()
81 throws JspException
82 {
83 Converter converter = null;
84
85 FacesContext facesContext = FacesContext.getCurrentInstance();
86 ELContext elContext = facesContext.getELContext();
87
88
89
90 if (_binding != null)
91 {
92 try
93 {
94 converter = (Converter) _binding.getValue(elContext);
95
96 if (converter != null)
97 {
98 return converter;
99 }
100 }
101 catch (Exception e)
102 {
103 throw new JspException("Exception creating converter using binding", e);
104 }
105 }
106
107 if ((_converterId != null) || (_converterIdString != null))
108 {
109 try
110 {
111 if (null != _converterIdString)
112 {
113 converter = facesContext.getApplication().createConverter(_converterIdString);
114 } else
115 {
116 String converterId = (String) _converterId.getValue(elContext);
117 converter = facesContext.getApplication().createConverter(converterId);
118 }
119
120
121
122 if (converter != null && _binding != null)
123 {
124 _binding.setValue(elContext, converter);
125 }
126 }
127 catch (Exception e)
128 {
129 throw new JspException("Exception creating converter with converterId: " + _converterId, e);
130 }
131 }
132
133 return converter;
134 }
135
136 }