KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > paneltabset > 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
17 package com.icesoft.faces.component.paneltabset;
18
19 import com.icesoft.faces.component.util.CustomComponentUtils;
20
21 import javax.faces.component.UIComponent;
22 import javax.faces.context.FacesContext;
23 import javax.faces.el.ValueBinding;
24 import javax.faces.webapp.UIComponentTag;
25 import javax.servlet.jsp.JspException JavaDoc;
26 import javax.servlet.jsp.tagext.Tag JavaDoc;
27 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
28
29 /**
30  * Tag to add tab change listeners to a com.icesoft.faces.component.paneltabset.PanelTabSet
31  */

32 public class TabChangeListenerTag extends TagSupport JavaDoc {
33     /**
34      * The serialVersionUID unique identifier.
35      */

36     private static final long serialVersionUID = -6903749011638483023L;
37     /**
38      * The current type.
39      */

40     private String JavaDoc type = null;
41
42     /**
43      * Creates an instance.
44      */

45     public TabChangeListenerTag() {
46
47     }
48
49     /**
50      * Sets the type.
51      *
52      * @param type
53      */

54     public void setType(String JavaDoc type) {
55
56         this.type = type;
57     }
58
59     /**
60      * @return Tag.SKIP_BODY
61      * @throws JspException
62      */

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