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.faces.component.UIComponent;
22  import javax.servlet.jsp.JspException;
23  
24  import org.apache.myfaces.shared_tomahawk.taglib.UIComponentTagBase;
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  
28  /**
29   * @author Sylvain Vieujot (latest modification by $Author: lu4242 $)
30   * @version $Revision: 671015 $ $Date: 2008-06-23 23:22:49 -0500 (Mon, 23 Jun 2008) $
31   */
32  public class AliasBeanTag extends UIComponentTagBase {
33  
34      private Log log = LogFactory.getLog(AliasBeanTag.class);
35  
36      private String _alias;
37      private String _valueExpression;
38  
39      public void release() {
40          super.release();
41  
42          _alias=null;
43          _valueExpression=null;
44  
45      }
46  
47      protected void setProperties(UIComponent component) {
48          super.setProperties(component);
49  
50          setValueBinding(component, "alias", _alias);
51          setStringProperty(component, "value", _valueExpression);
52      }
53  
54      public String getComponentType() {
55          return AliasBean.COMPONENT_TYPE;
56      }
57  
58      public String getRendererType() {
59          return null;
60      }
61  
62      public void setAlias(String alias){
63          _alias = alias;
64      }
65  
66      public void setValue(String valueExpression){
67          _valueExpression = valueExpression;
68      }
69  
70      public int doStartTag() throws JspException
71      {
72          int retVal= super.doStartTag();
73  
74          UIComponent comp = getComponentInstance();
75  
76          if(comp instanceof AliasBean)
77          {
78              ((AliasBean) comp).makeAlias(getFacesContext());
79          }
80          else
81          {
82              log.warn("associated component is no aliasBean");
83          }
84  
85          return retVal;
86      }
87  
88      public int doEndTag() throws JspException
89      {
90          UIComponent comp = getComponentInstance();
91  
92          if(comp instanceof AliasBean)
93          {
94              ((AliasBean) comp).removeAlias(getFacesContext());
95          }
96          else
97          {
98              log.warn("associated component is no aliasBean");
99          }
100 
101         return super.doEndTag();
102     }
103 }