1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.tag.jsf;
20
21 import java.io.IOException;
22
23 import javax.el.ELException;
24 import javax.el.ValueExpression;
25 import javax.faces.FacesException;
26 import javax.faces.component.UIComponent;
27 import javax.faces.component.ValueHolder;
28 import javax.faces.context.FacesContext;
29 import javax.faces.convert.Converter;
30 import javax.faces.view.facelets.ConverterConfig;
31 import javax.faces.view.facelets.FaceletContext;
32 import javax.faces.view.facelets.FaceletException;
33 import javax.faces.view.facelets.MetaRuleset;
34 import javax.faces.view.facelets.TagAttribute;
35 import javax.faces.view.facelets.TagConfig;
36 import javax.faces.view.facelets.TagException;
37
38 import org.apache.myfaces.view.facelets.tag.MetaTagHandlerImpl;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 @Deprecated
54 public class ConvertHandler extends MetaTagHandlerImpl
55 {
56
57 private final TagAttribute binding;
58
59 private String converterId;
60
61
62
63
64
65 public ConvertHandler(TagConfig config)
66 {
67 super(config);
68 this.binding = this.getAttribute("binding");
69 this.converterId = null;
70 }
71
72 public ConvertHandler(ConverterConfig config)
73 {
74 this((TagConfig) config);
75 this.converterId = config.getConverterId();
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 public final void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException,
95 FaceletException, ELException
96 {
97 if (parent == null || !(parent instanceof ValueHolder))
98 {
99 throw new TagException(this.tag, "Parent not an instance of ValueHolder: " + parent);
100 }
101
102
103 if (parent.getParent() == null)
104 {
105
106 ValueHolder vh = (ValueHolder) parent;
107 ValueExpression ve = null;
108 Converter c = null;
109 if (this.binding != null)
110 {
111 ve = this.binding.getValueExpression(ctx, Converter.class);
112 c = (Converter) ve.getValue(ctx);
113 }
114 if (c == null)
115 {
116 c = this.createConverter(ctx);
117 if (ve != null)
118 {
119 ve.setValue(ctx, c);
120 }
121 }
122 if (c == null)
123 {
124 throw new TagException(this.tag, "No Converter was created");
125 }
126 this.setAttributes(ctx, c);
127 vh.setConverter(c);
128 Object lv = vh.getLocalValue();
129 FacesContext faces = ctx.getFacesContext();
130 if (lv instanceof String)
131 {
132 vh.setValue(c.getAsObject(faces, parent, (String) lv));
133 }
134 }
135 }
136
137
138
139
140
141
142
143
144 protected Converter createConverter(FaceletContext ctx)
145 {
146 if (this.converterId == null)
147 {
148 throw new TagException(this.tag,
149 "Default behavior invoked of requiring a converter-id passed in the constructor, "
150 + "must override ConvertHandler(ConverterConfig)");
151 }
152 return ctx.getFacesContext().getApplication().createConverter(this.converterId);
153 }
154
155 protected MetaRuleset createMetaRuleset(Class type)
156 {
157 return super.createMetaRuleset(type).ignore("binding");
158 }
159 }