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.custom.aliasbean;
20  
21  import javax.el.ValueExpression;
22  import javax.faces.component.UIComponent;
23  import javax.faces.webapp.UIComponentELTag;
24  import javax.servlet.jsp.JspException;
25  
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  /**
30   * @author Sylvain Vieujot (latest modification by $Author: lu4242 $)
31   * @version $Revision: 664402 $ $Date: 2008-06-07 16:59:02 -0500 (Sat, 07 Jun 2008) $
32   */
33  public class AliasBeanTag extends UIComponentELTag
34  {
35  
36      private Log log = LogFactory.getLog(AliasBeanTag.class);
37      /**
38       * Construct an instance of the AliasBeanELTag.
39       */
40      public AliasBeanTag()
41      {
42      }
43      
44      public int doStartTag() throws JspException
45      {
46          int retVal= super.doStartTag();
47  
48          UIComponent comp = getComponentInstance();
49  
50          if(comp instanceof AliasBean)
51          {
52              ((AliasBean) comp).makeAlias(getFacesContext());
53          }
54          else
55          {
56              log.warn("associated component is no aliasBean");
57          }
58  
59          return retVal;
60      }
61  
62      public int doEndTag() throws JspException
63      {
64          UIComponent comp = getComponentInstance();
65  
66          if(comp instanceof AliasBean)
67          {
68              ((AliasBean) comp).removeAlias(getFacesContext());
69          }
70          else
71          {
72              log.warn("associated component is no aliasBean");
73          }
74  
75          return super.doEndTag();
76      }
77      
78      @Override
79      public String getComponentType()
80      {
81          return "org.apache.myfaces.AliasBean";
82      }
83  
84      public String getRendererType()
85      {
86          return null;
87      }
88  
89      private ValueExpression _alias;
90  
91      public void setAlias(ValueExpression alias)
92      {
93          _alias = alias;
94      }
95  
96      private ValueExpression _value;
97  
98      public void setValue(ValueExpression value)
99      {
100         _value = value;
101     }
102 
103     @Override
104     protected void setProperties(UIComponent component)
105     {
106         if (!(component instanceof AliasBean))
107         {
108             throw new IllegalArgumentException("Component "
109                     + component.getClass().getName() + " is no AliasBean");
110         }
111         AliasBean comp = (AliasBean) component;
112 
113         super.setProperties(component);
114 
115         if (_alias != null)
116         {
117             comp.setValueExpression("alias", _alias);
118         }
119         if (_value != null)
120         {
121             comp.setValueExpression("value", _value);
122         }
123     }
124 
125     @Override
126     public void release()
127     {
128         super.release();
129         _alias = null;
130         _value = null;
131     }
132 }