1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.internal.taglib;
21
22 import org.apache.commons.beanutils.PropertyUtils;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.apache.myfaces.tobago.component.Attributes;
26 import org.apache.myfaces.tobago.component.InputSuggest;
27 import org.apache.myfaces.tobago.el.ConstantMethodBinding;
28 import org.apache.myfaces.tobago.event.SheetStateChangeSource;
29 import org.apache.myfaces.tobago.event.SortActionSource;
30 import org.apache.myfaces.tobago.event.TabChangeSource;
31 import org.apache.myfaces.tobago.internal.component.AbstractUIMessages;
32 import org.apache.myfaces.tobago.internal.component.AbstractUIPage;
33 import org.apache.myfaces.tobago.internal.component.AbstractUIPopup;
34 import org.apache.myfaces.tobago.util.ComponentUtils;
35
36 import javax.faces.application.Application;
37 import javax.faces.component.ActionSource;
38 import javax.faces.component.EditableValueHolder;
39 import javax.faces.component.UIComponent;
40 import javax.faces.component.ValueHolder;
41 import javax.faces.context.FacesContext;
42 import javax.faces.convert.Converter;
43 import javax.faces.el.MethodBinding;
44 import javax.faces.el.ValueBinding;
45 import javax.faces.webapp.UIComponentTag;
46 import java.lang.reflect.InvocationTargetException;
47
48
49
50
51 @Deprecated
52 public class TagUtils {
53 private static final Logger LOG = LoggerFactory.getLogger(TagUtils.class);
54
55
56
57
58 @Deprecated
59 public static void setIntegerProperty(UIComponent component, String name, String value) {
60 if (value != null) {
61 if (UIComponentTag.isValueReference(value)) {
62 component.setValueBinding(name, createValueBinding(value));
63 } else {
64 if ((component instanceof AbstractUIPage
65 || component instanceof javax.faces.component.UIGraphic
66 || component instanceof AbstractUIPopup)
67 && (Attributes.WIDTH.equals(name) || Attributes.HEIGHT.equals(name))) {
68 if (value.endsWith("px")) {
69 value = value.substring(0, value.length() - 2);
70 }
71 }
72 component.getAttributes().put(name, new Integer(value));
73 }
74 }
75 }
76
77
78
79
80 @Deprecated
81 public static void setBooleanProperty(UIComponent component, String name, String value) {
82 if (value != null) {
83 if (UIComponentTag.isValueReference(value)) {
84 component.setValueBinding(name, createValueBinding(value));
85 } else {
86 component.getAttributes().put(name, Boolean.valueOf(value));
87 }
88 }
89 }
90
91
92
93
94 @Deprecated
95 public static void setStringProperty(UIComponent component, String name, String value) {
96 if (value != null) {
97 if (UIComponentTag.isValueReference(value)) {
98 component.setValueBinding(name, createValueBinding(value));
99 } else {
100 component.getAttributes().put(name, value);
101 }
102 }
103 }
104
105
106
107
108 @Deprecated
109 public static void setConverterProperty(UIComponent component, String name, String value) {
110 if (value != null && component instanceof ValueHolder) {
111 final FacesContext facesContext = FacesContext.getCurrentInstance();
112 final Application application = facesContext.getApplication();
113 if (UIComponentTag.isValueReference(value)) {
114 ValueBinding valueBinding = application.createValueBinding(value);
115 component.setValueBinding(name, valueBinding);
116 } else {
117 Converter converter = application.createConverter(value);
118 ((ValueHolder) component).setConverter(converter);
119 }
120 }
121 }
122
123
124
125
126 @Deprecated
127 public static void setSeverityProperty(UIComponent component, String name, String value) {
128 setStringProperty(component, name, value);
129 }
130
131
132
133
134 @Deprecated
135 public static void setObjectProperty(UIComponent component, String name, String value) {
136 setStringProperty(component, name, value);
137 }
138
139
140
141
142 @Deprecated
143 public static void setCharacterProperty(UIComponent component, String name, String value) {
144 setStringProperty(component, name, value);
145 }
146
147
148
149
150 @Deprecated
151 public static ValueBinding createValueBinding(String value) {
152 return FacesContext.getCurrentInstance().getApplication().createValueBinding(value);
153 }
154
155
156
157
158 @Deprecated
159 public static void setStateChangeListenerMethodBinding(UIComponent component, String value, Class[] args) {
160 if (value != null && UIComponentTag.isValueReference(value)) {
161 MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
162 ((SheetStateChangeSource) component).setStateChangeListener(methodBinding);
163 }
164 }
165
166
167
168
169 @Deprecated
170 public static void setSortActionListenerMethodBinding(UIComponent component, String value, Class[] args) {
171 if (value != null && UIComponentTag.isValueReference(value)) {
172 MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
173 ((SortActionSource) component).setSortActionListener(methodBinding);
174 }
175 }
176
177
178
179
180 @Deprecated
181 public static void setSuggestMethodMethodBinding(UIComponent component, String value, Class[] args) {
182 if (value != null && UIComponentTag.isValueReference(value)) {
183 MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
184 ((InputSuggest) component).setSuggestMethod(methodBinding);
185 }
186 }
187
188
189
190
191 @Deprecated
192 public static void setValueChangeListenerMethodBinding(UIComponent component, String value, Class[] args) {
193 if (value != null && UIComponentTag.isValueReference(value)) {
194 MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
195 ((EditableValueHolder) component).setValueChangeListener(methodBinding);
196 }
197 }
198
199
200
201
202 @Deprecated
203 public static void setValidatorMethodBinding(UIComponent component, String value, Class[] args) {
204 if (value != null && UIComponentTag.isValueReference(value)) {
205 MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
206 ((EditableValueHolder) component).setValidator(methodBinding);
207 }
208 }
209
210
211
212
213 @Deprecated
214 public static void setActionListenerMethodBinding(UIComponent component, String value, Class[] args) {
215 if (value != null && UIComponentTag.isValueReference(value)) {
216 MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
217 ((ActionSource) component).setActionListener(methodBinding);
218 }
219 }
220
221
222
223
224 @Deprecated
225 public static void setActionMethodBinding(UIComponent component, String value, Class[] args) {
226 if (value != null) {
227 if (UIComponentTag.isValueReference(value)) {
228 MethodBinding methodBinding =
229 FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
230 ((ActionSource) component).setAction(methodBinding);
231 } else {
232 ((ActionSource) component).setAction(new ConstantMethodBinding(value));
233 }
234 }
235 }
236
237
238
239
240 @Deprecated
241 public static void setTabChangeListenerMethodBinding(UIComponent component, String value, Class[] args) {
242 if (value != null && UIComponentTag.isValueReference(value)) {
243 MethodBinding methodBinding = FacesContext.getCurrentInstance().getApplication().createMethodBinding(value, args);
244 ((TabChangeSource) component).setTabChangeListener(methodBinding);
245 }
246 }
247
248
249
250
251 @Deprecated
252 public static void setStringArrayProperty(UIComponent component, String name, String value) {
253 if (value != null) {
254 if (UIComponentTag.isValueReference(value)) {
255 component.setValueBinding(name, createValueBinding(value));
256 } else {
257 String[] components = ComponentUtils.splitList(value);
258 try {
259 PropertyUtils.setProperty(component, name, components);
260 } catch (IllegalAccessException e) {
261 LOG.error("Ignoring Property", e);
262 } catch (InvocationTargetException e) {
263 LOG.error("Ignoring Property", e);
264 } catch (NoSuchMethodException e) {
265 LOG.error("Ignoring Property", e);
266 }
267 }
268 }
269 }
270
271
272
273
274 @Deprecated
275 public static void setValueBindingProperty(UIComponent component, String name, String value) {
276 if (value != null && UIComponentTag.isValueReference(value)) {
277 ValueBinding valueBinding = createValueBinding(value);
278 component.setValueBinding(name, valueBinding);
279 }
280 }
281
282
283
284
285 @Deprecated
286 public static void setOrderByProperty(UIComponent component, String name, String value) {
287 if (value != null) {
288 if (UIComponentTag.isValueReference(value)) {
289 component.setValueBinding(name, createValueBinding(value));
290 } else {
291 component.getAttributes().put(name, AbstractUIMessages.OrderBy.parse(value));
292 }
293 }
294 }
295
296
297
298
299 @Deprecated
300 public static String getValueFromEl(String script) {
301 if (UIComponentTag.isValueReference(script)) {
302 ValueBinding valueBinding = createValueBinding(script);
303 script = (String) valueBinding.getValue(FacesContext.getCurrentInstance());
304 }
305 return script;
306 }
307 }