KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > tabbedpane > TabChangeListenerTag


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.custom.tabbedpane;
17
18 import javax.faces.component.UIComponent;
19 import javax.faces.context.FacesContext;
20 import javax.faces.el.ValueBinding;
21 import javax.faces.webapp.UIComponentTag;
22 import javax.servlet.jsp.JspException JavaDoc;
23 import javax.servlet.jsp.tagext.Tag JavaDoc;
24 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
25
26 import org.apache.myfaces.util.ClassUtils;
27
28
29 /**
30  * Tag to add a tab change listeners to a {@link org.apache.myfaces.custom.tabbedpane.HtmlPanelTabbedPane]
31  *
32  * @author <a HREF="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
33  * @version $Revision: 1.3 $ $Date: 2004/10/13 11:50:58 $
34  * $Log: TabChangeListenerTag.java,v $
35  * Revision 1.3 2004/10/13 11:50:58 matze
36  * renamed packages to org.apache
37  *
38  * Revision 1.2 2004/09/01 18:32:56 mwessendorf
39  * Organize Imports
40  *
41  * Revision 1.1 2004/08/09 22:01:38 o_rossmueller
42  * tagChangeListener tag
43  *
44  * Revision 1.2 2004/07/01 21:53:06 mwessendorf
45  * ASF switch
46  *
47  * Revision 1.1 2004/04/22 21:14:55 o_rossmueller
48  * TreeSelectionListener support
49  *
50  */

51 public class TabChangeListenerTag extends TagSupport JavaDoc
52 {
53
54     private String JavaDoc type = null;
55
56
57     public TabChangeListenerTag()
58     {
59     }
60
61
62     public void setType(String JavaDoc type)
63     {
64         this.type = type;
65     }
66
67
68     public int doStartTag() throws JspException JavaDoc
69     {
70         if (type == null)
71         {
72             throw new JspException JavaDoc("type attribute not set");
73         }
74
75         //Find parent UIComponentTag
76
UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext);
77         if (componentTag == null)
78         {
79             throw new JspException JavaDoc("TabChangeListenerTag has no UIComponentTag ancestor");
80         }
81
82         if (componentTag.getCreated())
83         {
84             //Component was just created, so we add the Listener
85
UIComponent component = componentTag.getComponentInstance();
86             if (component instanceof HtmlPanelTabbedPane)
87             {
88                 String JavaDoc className;
89                 if (UIComponentTag.isValueReference(type))
90                 {
91                     FacesContext facesContext = FacesContext.getCurrentInstance();
92                     ValueBinding valueBinding = facesContext.getApplication().createValueBinding(type);
93                     className = (String JavaDoc) valueBinding.getValue(facesContext);
94                 } else
95                 {
96                     className = type;
97                 }
98                 TabChangeListener listener = (TabChangeListener) ClassUtils.newInstance(className);
99                 ((HtmlPanelTabbedPane) component).addTabChangeListener(listener);
100             } else
101             {
102                 throw new JspException JavaDoc("Component " + component.getId() + " is no HtmlPanelTabbedPane");
103             }
104         }
105
106         return Tag.SKIP_BODY;
107     }
108 }
109
Popular Tags