1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.custom.tabbedpane;
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;
26 import javax.servlet.jsp.tagext.Tag;
27 import javax.servlet.jsp.tagext.TagSupport;
28
29 import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class TabChangeListenerTag extends TagSupport
44 {
45 private static final long serialVersionUID = -6903749011638483023L;
46 private String type = null;
47
48
49 public TabChangeListenerTag()
50 {
51 }
52
53
54
55
56
57 public void setType(String type)
58 {
59 this.type = type;
60 }
61
62
63 public int doStartTag() throws JspException
64 {
65 if (type == null)
66 {
67 throw new JspException("type attribute not set");
68 }
69
70
71 UIComponentTag componentTag = UIComponentTag.getParentUIComponentTag(pageContext);
72 if (componentTag == null)
73 {
74 throw new JspException("TabChangeListenerTag has no UIComponentTag ancestor");
75 }
76
77 if (componentTag.getCreated())
78 {
79
80 UIComponent component = componentTag.getComponentInstance();
81 if (component instanceof HtmlPanelTabbedPane)
82 {
83 Object listenerRef = type;
84 if (UIComponentTag.isValueReference(type))
85 {
86 FacesContext facesContext = FacesContext.getCurrentInstance();
87 ValueBinding valueBinding = facesContext.getApplication().createValueBinding(type);
88 listenerRef = valueBinding.getValue(facesContext);
89 }
90
91 if(listenerRef instanceof String)
92 {
93 String className = (String) listenerRef;
94 TabChangeListener listener = (TabChangeListener) ClassUtils.newInstance(className);
95 ((HtmlPanelTabbedPane) component).addTabChangeListener(listener);
96 }
97 else if(listenerRef instanceof TabChangeListener)
98 {
99 TabChangeListener listener = (TabChangeListener) listenerRef;
100 ((HtmlPanelTabbedPane) component).addTabChangeListener(listener);
101
102 }
103 else
104 throw new JspException("type is neither a 'String' nor a value-binding to a 'String' or a 'TabChangeListener' instance.");
105 }
106 else
107 {
108 throw new JspException("Component " + component.getId() + " is no HtmlPanelTabbedPane");
109 }
110 }
111
112 return Tag.SKIP_BODY;
113 }
114 }