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  package org.apache.myfaces.shared.taglib;
20  
21  import org.apache.myfaces.shared.renderkit.JSFAttr;
22  
23  import javax.el.MethodExpression;
24  import javax.el.ValueExpression;
25  import javax.faces.component.UIComponent;
26  import javax.faces.webapp.UIComponentELTag;
27  
28  public abstract class UIComponentELTagBase extends UIComponentELTag
29  {
30      //private static final Log log = LogFactory.getLog(UIComponentTagBase.class);
31  
32      //UIComponent attributes
33      private ValueExpression _forceId;
34  
35      private ValueExpression _forceIdIndex;
36      private static final Boolean DEFAULT_FORCE_ID_INDEX_VALUE = Boolean.TRUE;
37  
38      private ValueExpression _javascriptLocation;
39      private ValueExpression _imageLocation;
40      private ValueExpression _styleLocation;
41  
42      //Special UIComponent attributes (ValueHolder, ConvertibleValueHolder)
43      private ValueExpression _value;
44      private ValueExpression _converter;
45  
46      //attributes id, rendered and binding are handled by UIComponentTag
47  
48      public void release()
49      {
50          super.release();
51  
52          _forceId = null;
53          _forceIdIndex = null;
54  
55          _value = null;
56          _converter = null;
57  
58          _javascriptLocation = null;
59          _imageLocation = null;
60          _styleLocation = null;
61      }
62  
63      protected void setProperties(UIComponent component)
64      {
65          super.setProperties(component);
66  
67          setBooleanProperty(component,
68                  org.apache.myfaces.shared.renderkit.JSFAttr.FORCE_ID_ATTR,
69                  _forceId);
70          setBooleanProperty(
71                  component,
72                  org.apache.myfaces.shared.renderkit.JSFAttr.FORCE_ID_INDEX_ATTR,
73                  _forceIdIndex, DEFAULT_FORCE_ID_INDEX_VALUE);
74          if (_javascriptLocation != null)
75          {
76              setStringProperty(component, JSFAttr.JAVASCRIPT_LOCATION,
77                      _javascriptLocation);
78          }
79          if (_imageLocation != null)
80          {
81              setStringProperty(component, JSFAttr.IMAGE_LOCATION, _imageLocation);
82          }
83          if (_styleLocation != null)
84          {
85              setStringProperty(component, JSFAttr.STYLE_LOCATION, _styleLocation);
86          }
87  
88          //rendererType already handled by UIComponentTag
89  
90          setValueProperty(component, _value);
91          setConverterProperty(component, _converter);
92      }
93  
94      /**
95       * Sets the forceId attribute of the tag.  NOTE: Not every tag that extends this class will
96       * actually make use of this attribute.  Check the TLD to see which components actually
97       * implement it.
98       *
99       * @param aForceId The value of the forceId attribute.
100      */
101     public void setForceId(ValueExpression aForceId)
102     {
103         _forceId = aForceId;
104     }
105 
106     /**
107      * Sets the forceIdIndex attribute of the tag.  NOTE: Not every tag that extends this class will
108      * actually make use of this attribute.  Check the TLD to see which components actually implement it.
109      *
110      * @param aForceIdIndex The value of the forceIdIndex attribute.
111      */
112     public void setForceIdIndex(ValueExpression aForceIdIndex)
113     {
114         _forceIdIndex = aForceIdIndex;
115     }
116 
117     public void setValue(ValueExpression value)
118     {
119         _value = value;
120     }
121 
122     public void setConverter(ValueExpression converter)
123     {
124         _converter = converter;
125     }
126 
127     /**
128      * Sets the javascript location attribute of the tag.  NOTE: Not every tag that extends this class will
129      * actually make use of this attribute.  Check the TLD to see which components actually implement it.
130      *
131      * @param aJavascriptLocation The alternate javascript location to use.
132      */
133     public void setJavascriptLocation(ValueExpression aJavascriptLocation)
134     {
135         _javascriptLocation = aJavascriptLocation;
136     }
137 
138     /**
139      * Sets the image location attribute of the tag.  NOTE: Not every tag that extends this class will
140      * actually make use of this attribute.  Check the TLD to see which components actually implement it.
141      *
142      * @param aImageLocation The alternate image location to use.
143      */
144     public void setImageLocation(ValueExpression aImageLocation)
145     {
146         _imageLocation = aImageLocation;
147     }
148 
149     /**
150      * Sets the style location attribute of the tag.  NOTE: Not every tag that extends this class will
151      * actually make use of this attribute.  Check the TLD to see which components actually implement it.
152      *
153      * @param aStyleLocation The alternate style location to use.
154      */
155     public void setStyleLocation(ValueExpression aStyleLocation)
156     {
157         _styleLocation = aStyleLocation;
158     }
159 
160     // sub class helpers
161 
162     protected void setIntegerProperty(UIComponent component, String propName,
163             ValueExpression value)
164     {
165         UIComponentELTagUtils.setIntegerProperty(component, propName, value);
166     }
167 
168     protected void setIntegerProperty(UIComponent component, String propName,
169             ValueExpression value, Integer defaultValue)
170     {
171         UIComponentELTagUtils.setIntegerProperty(component, propName, value,
172                 defaultValue);
173     }
174 
175     protected void setLongProperty(UIComponent component, String propName,
176             ValueExpression value)
177     {
178         UIComponentELTagUtils.setLongProperty(component, propName, value);
179     }
180 
181     protected void setLongProperty(UIComponent component, String propName,
182             ValueExpression value, Long defaultValue)
183     {
184         UIComponentELTagUtils.setLongProperty(component, propName, value,
185                 defaultValue);
186     }
187 
188     @Deprecated
189     protected void setStringProperty(UIComponent component, String propName,
190             String value)
191     {
192         UIComponentTagUtils.setStringProperty(getFacesContext(), component,
193                 propName, value);
194     }
195 
196     protected void setStringProperty(UIComponent component, String propName,
197             ValueExpression value)
198     {
199         UIComponentELTagUtils.setStringProperty(component, propName, value);
200     }
201 
202     protected void setStringProperty(UIComponent component, String propName,
203             ValueExpression value, String defaultValue)
204     {
205         UIComponentELTagUtils.setStringProperty(component, propName, value,
206                 defaultValue);
207     }
208 
209     @Deprecated
210     protected void setBooleanProperty(UIComponent component, String propName,
211             String value)
212     {
213         UIComponentTagUtils.setBooleanProperty(getFacesContext(), component,
214                 propName, value);
215     }
216 
217     protected void setBooleanProperty(UIComponent component, String propName,
218             ValueExpression value)
219     {
220         UIComponentELTagUtils.setBooleanProperty(component, propName, value);
221     }
222 
223     protected void setBooleanProperty(UIComponent component, String propName,
224             ValueExpression value, Boolean defaultValue)
225     {
226         UIComponentELTagUtils.setBooleanProperty(component, propName, value,
227                 defaultValue);
228     }
229 
230     private void setValueProperty(UIComponent component, ValueExpression value)
231     {
232         UIComponentELTagUtils.setValueProperty(getFacesContext(), component,
233                 value);
234     }
235 
236     private void setConverterProperty(UIComponent component,
237             ValueExpression value)
238     {
239         UIComponentELTagUtils.setConverterProperty(getFacesContext(),
240                 component, value);
241     }
242 
243     protected void addValidatorProperty(UIComponent component,
244             MethodExpression value)
245     {
246         UIComponentELTagUtils.addValidatorProperty(getFacesContext(),
247                 component, value);
248     }
249 
250     @Deprecated
251     protected void setActionProperty(UIComponent component, String action)
252     {
253         UIComponentTagUtils.setActionProperty(getFacesContext(), component,
254                 action);
255     }
256 
257     protected void setActionProperty(UIComponent component,
258             MethodExpression action)
259     {
260         UIComponentELTagUtils.setActionProperty(getFacesContext(), component,
261                 action);
262     }
263 
264     @Deprecated
265     protected void setActionListenerProperty(UIComponent component,
266             String actionListener)
267     {
268         UIComponentTagUtils.setActionListenerProperty(getFacesContext(),
269                 component, actionListener);
270     }
271 
272     protected void setActionListenerProperty(UIComponent component,
273             MethodExpression actionListener)
274     {
275         UIComponentELTagUtils.addActionListenerProperty(getFacesContext(),
276                 component, actionListener);
277     }
278 
279     protected void addValueChangedListenerProperty(UIComponent component,
280             MethodExpression valueChangedListener)
281     {
282         UIComponentELTagUtils.addValueChangedListenerProperty(
283                 getFacesContext(), component, valueChangedListener);
284     }
285 
286     protected void setValueBinding(UIComponent component, String propName,
287             ValueExpression value)
288     {
289         UIComponentELTagUtils.setValueBinding(getFacesContext(), component,
290                 propName, value);
291     }
292 
293     protected Object evaluateValueExpression(ValueExpression expression)
294     {
295         return UIComponentELTagUtils.evaluateValueExpression(getFacesContext()
296                 .getELContext(), expression);
297     }
298 
299 }