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 javax.faces.webapp;
20  
21  import javax.el.ValueExpression;
22  import javax.faces.application.Application;
23  import javax.faces.component.UIComponent;
24  import javax.faces.context.FacesContext;
25  import javax.servlet.jsp.JspException;
26  
27  /**
28   * Base class for all JSP tags that represent a JSF UIComponent.
29   * <p>
30   * <i>Disclaimer</i>: The official definition for the behaviour of this class is the JSF specification but for legal
31   * reasons the specification cannot be replicated here. Any javadoc present on this class therefore describes the
32   * current implementation rather than the officially required behaviour, though it is believed that this class does
33   * comply with the specification.
34   * 
35   * see Javadoc of <a href="http://java.sun.com/j2ee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a> for
36   * more.
37   * 
38   * @since 1.2
39   */
40  public abstract class UIComponentELTag extends UIComponentClassicTagBase
41  {
42  
43      private ValueExpression _binding = null;
44      private ValueExpression _rendered = null;
45  
46      public UIComponentELTag()
47      {
48  
49      }
50  
51      @Override
52      public void release()
53      {
54          super.release();
55          _binding = null;
56          _rendered = null;
57      }
58  
59      @Override
60      protected void setProperties(UIComponent component)
61      {
62          if (getRendererType() != null)
63          {
64              component.setRendererType(getRendererType());
65          }
66  
67          if (_rendered != null)
68          {
69              if (_rendered.isLiteralText())
70              {
71                  boolean b = Boolean.valueOf(_rendered.getExpressionString()).booleanValue();
72                  component.setRendered(b);
73              }
74              else
75              {
76                  component.setValueExpression("rendered", _rendered);
77              }
78          }
79      }
80  
81      @Override
82      protected UIComponent createComponent(FacesContext context, String newId) throws JspException
83      {
84          UIComponent component;
85          Application application = context.getApplication();
86  
87          if (_binding != null)
88          {
89              component = application.createComponent(_binding, context, getComponentType());
90              component.setValueExpression("binding", _binding);
91          }
92          else
93          {
94              component = application.createComponent(getComponentType());
95          }
96  
97          component.setId(newId);
98          setProperties(component);
99  
100         return component;
101     }
102 
103     /**
104      * @throws JspException  
105      */
106     public void setBinding(ValueExpression binding) throws JspException
107     {
108         _binding = binding;
109     }
110 
111     @Override
112     protected boolean hasBinding()
113     {
114         return _binding != null;
115     }
116 
117     public void setRendered(ValueExpression rendered)
118     {
119         _rendered = rendered;
120     }
121 }