View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.compat;
21  
22  import org.apache.myfaces.tobago.event.TabChangeSource;
23  import org.apache.myfaces.tobago.util.FacesVersion;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  import javax.faces.component.ActionSource;
28  import javax.faces.component.ContextCallback;
29  import javax.faces.component.EditableValueHolder;
30  import javax.faces.component.UIComponent;
31  import javax.faces.component.ValueHolder;
32  import javax.faces.context.FacesContext;
33  import javax.faces.el.EvaluationException;
34  import javax.faces.el.MethodBinding;
35  import javax.faces.event.AbortProcessingException;
36  import javax.faces.event.FacesEvent;
37  import java.util.Comparator;
38  import java.util.Map;
39  
40  @SuppressWarnings("deprecation")
41  public class FacesUtils {
42  
43    private static final Logger LOG = LoggerFactory.getLogger(FacesUtilsEL.class);
44  
45    /**
46     * @deprecated since 1.6.0
47     */
48    @Deprecated
49    public static final Class[] VALIDATOR_ARGS = {FacesContext.class, UIComponent.class, Object.class};
50  
51    /**
52     * @deprecated since 1.6.0. Please use ComponentUtils.invokeOnComponent(context, this, clientId, callback)
53     */
54    @Deprecated
55    public static boolean invokeOnComponent(
56        FacesContext context, UIComponent component, String clientId, ContextCallback callback) {
57      return FacesInvokeOnComponent12.invokeOnComponent(context, component, clientId, callback);
58    }
59  
60    public static void invokeMethodBinding(FacesContext facesContext, MethodBinding methodBinding, FacesEvent event) {
61      if (methodBinding != null && event != null) {
62        try {
63          methodBinding.invoke(facesContext, new Object[]{event});
64        } catch (EvaluationException e) {
65          Throwable cause = e.getCause();
66          if (cause instanceof AbortProcessingException) {
67            throw (AbortProcessingException) cause;
68          } else {
69            throw e;
70          }
71        }
72      }
73    }
74  
75    /**
76     * @deprecated since 1.6.0
77     */
78    @Deprecated
79    public static Object getValueFromValueBindingOrValueExpression(
80        FacesContext context, UIComponent component, String name) {
81        return FacesUtilsEL.getValueFromValueBindingOrValueExpression(context, component, name);
82    }
83  
84    /**
85     * @deprecated since 1.6.0
86     */
87    @Deprecated
88    public static boolean hasValueBindingOrValueExpression(UIComponent component, String name) {
89        return FacesUtilsEL.hasValueBindingOrValueExpression(component, name);
90    }
91  
92    /**
93     * @deprecated since 1.6.0
94     */
95    @Deprecated
96    public static boolean isReadonlyValueBindingOrValueExpression(
97        FacesContext context, UIComponent component, String name) {
98        return FacesUtilsEL.isReadonlyValueBindingOrValueExpression(context, component, name);
99    }
100 
101   /**
102    * @deprecated since 1.6.0
103    */
104   @Deprecated
105   public static String getExpressionString(UIComponent component, String name) {
106       return FacesUtilsEL.getExpressionString(component, name);
107   }
108 
109   /**
110    * @deprecated since 1.6.0
111    */
112   @Deprecated
113   public static void setValueOfBindingOrExpression(
114       FacesContext context, Object value, UIComponent component, String bindingName) {
115       FacesUtilsEL.setValueOfBindingOrExpression(context, value, component, bindingName);
116   }
117 
118   /**
119    * @deprecated since 1.6.0
120    */
121   @Deprecated
122   public static void setValueOfBindingOrExpression(
123       FacesContext context, Object value, Object bindingOrExpression) {
124       FacesUtilsEL.setValueOfBindingOrExpression(context, value, bindingOrExpression);
125   }
126 
127   /**
128    * @deprecated since 1.6.0
129    */
130   @Deprecated
131   public static void copyValueBindingOrValueExpression(
132       UIComponent fromComponent, String fromName, UIComponent toComponent, String toName) {
133       FacesUtilsEL.copyValueBindingOrValueExpression(fromComponent, fromName, toComponent, toName);
134   }
135 
136   /**
137    * @deprecated since 1.6.0
138    */
139   @Deprecated
140   public static Object getValueFromBindingOrExpression(Object obj) {
141       return FacesUtilsEL.getValueFromBindingOrExpression(obj);
142   }
143 
144   /**
145    * @deprecated since 1.6.0
146    */
147   @Deprecated
148   public static Object createExpressionOrBinding(String string) {
149       return FacesUtilsEL.createExpressionOrBinding(string);
150   }
151 
152   /**
153    * @deprecated since 1.6.0
154    */
155   @Deprecated
156   public static void setValidator(EditableValueHolder editableValueHolder, Object validator) {
157       FacesUtilsEL.setValidator(editableValueHolder, validator);
158   }
159 
160   /**
161    * @deprecated since 1.6.0
162    */
163   @Deprecated
164   public static void setConverter(ValueHolder valueHolder, Object converterExpression) {
165       FacesUtilsEL.setConverter(valueHolder, converterExpression);
166   }
167 
168   /**
169    * @deprecated since 1.6.0
170    */
171   @Deprecated
172   public static void setBindingOrExpression(UIComponent component, String name, Object valueBindingOrExpression) {
173       FacesUtilsEL.setBindingOrExpression(component, name, valueBindingOrExpression);
174   }
175 
176   /**
177    * @deprecated since 1.6.0
178    */
179   @Deprecated
180   public static void setBindingOrExpression(UIComponent component, String name, String valueBindingOrExpression) {
181     setBindingOrExpression(component, name, createExpressionOrBinding(valueBindingOrExpression));
182   }
183 
184   /**
185    * @deprecated since 1.6.0
186    */
187   @Deprecated
188   public static void addBindingOrExpressionTabChangeListener(TabChangeSource source, String type,
189       Object bindingOrExpression) {
190       FacesUtilsEL.addBindingOrExpressionTabChangeListener(source, type, bindingOrExpression);
191   }
192 
193   /**
194    * @deprecated since 1.6.0
195    */
196   @Deprecated
197   public static Comparator getBindingOrExpressionComparator(
198       FacesContext facesContext, UIComponent child, String var, boolean descending, Comparator comparator) {
199       return FacesUtilsEL.getBindingOrExpressionComparator(facesContext, child, var, descending, comparator);
200   }
201 
202   /**
203    * @deprecated since 1.6.0
204    */
205   @Deprecated
206   public static void addBindingOrExpressionPopupActionListener(ActionSource actionSource, Object bindingOrExpression) {
207       FacesUtilsEL.addBindingOrExpressionPopupActionListener(actionSource, bindingOrExpression);
208   }
209 
210   /**
211    * @deprecated since 1.6.0
212    */
213   @Deprecated
214   public static void addBindingOrExpressionResetActionListener(ActionSource actionSource, Object bindingOrExpression) {
215       FacesUtilsEL.addBindingOrExpressionResetActionListener(actionSource, bindingOrExpression);
216   }
217 
218   public static Map getFacesContextAttributes(FacesContext context) {
219     if (FacesVersion.supports20()) {
220       return context.getAttributes();
221     } else {
222       return context.getExternalContext().getRequestMap();
223     }
224   }
225 
226   /**
227    * @deprecated since 1.6.0. Always true.
228    */
229   @Deprecated
230   public static boolean supportsEL() {
231     return true;
232   }
233 }