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 java.io.IOException;
22
23 import javax.el.ELException;
24 import javax.faces.FacesException;
25 import javax.faces.component.UIComponent;
26
27 import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
28
29 import com.sun.facelets.FaceletContext;
30 import com.sun.facelets.FaceletException;
31 import com.sun.facelets.tag.TagAttribute;
32 import com.sun.facelets.tag.TagConfig;
33 import com.sun.facelets.tag.TagHandler;
34
35
36
37
38
39
40 public class TabChangeListenerTagHandler extends TagHandler
41 {
42 private final TagAttribute typeAttr;
43
44 public TabChangeListenerTagHandler(TagConfig config)
45 {
46 super(config);
47 typeAttr = getRequiredAttribute("type");
48 }
49
50 public void apply(FaceletContext faceletContext, UIComponent parent)
51 throws IOException, FacesException, FaceletException, ELException
52 {
53
54 if (parent.getParent() == null)
55 {
56 if (parent instanceof HtmlPanelTabbedPane)
57 {
58 Object listenerRef;
59 if (typeAttr.isLiteral())
60 {
61 listenerRef = typeAttr.getValue();
62 }
63 else
64 {
65 listenerRef = typeAttr.getObject(faceletContext);
66 }
67
68 if (listenerRef instanceof String)
69 {
70 String className = (String) listenerRef;
71 TabChangeListener listener = (TabChangeListener) ClassUtils.newInstance(className);
72 ((HtmlPanelTabbedPane) parent).addTabChangeListener(listener);
73 }
74 else if (listenerRef instanceof TabChangeListener)
75 {
76 TabChangeListener listener = (TabChangeListener) listenerRef;
77 ((HtmlPanelTabbedPane) parent).addTabChangeListener(listener);
78 }
79 else if (listenerRef == null)
80 {
81 throw new FaceletException("Property 'type' must not be null.");
82 }
83 else
84 {
85 throw new FaceletException(
86 "Property 'type' must be either a string (containing a class name) " +
87 "or a TabChangeListener instance.");
88 }
89 }
90 else
91 {
92 throw new FaceletException(
93 "Component " + parent.getId() + " is not of type HtmlPanelTabbedPane");
94 }
95 }
96 }
97 }