1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.custom.tree.taglib;
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.custom.tree.HtmlTree;
28 import org.apache.myfaces.custom.tree.event.TreeSelectionListener;
29 import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
30
31 import com.sun.facelets.FaceletContext;
32 import com.sun.facelets.FaceletException;
33 import com.sun.facelets.tag.TagAttribute;
34 import com.sun.facelets.tag.TagConfig;
35 import com.sun.facelets.tag.TagHandler;
36
37
38
39
40
41 public class TreeSelectionListenerTagHandler extends TagHandler
42 {
43
44 private final TagAttribute typeAttr;
45
46 public TreeSelectionListenerTagHandler(TagConfig config)
47 {
48 super(config);
49 typeAttr = getRequiredAttribute("type");
50 }
51
52 public void apply(FaceletContext faceletContext, UIComponent parent)
53 throws IOException, FacesException, FaceletException, ELException
54 {
55 if (parent.getParent() == null)
56 {
57 if (parent instanceof HtmlTree)
58 {
59 String className;
60 if (!typeAttr.isLiteral())
61 {
62 className = typeAttr.getValue();
63 }
64 else
65 {
66 className = typeAttr.getValue(faceletContext);
67 }
68 TreeSelectionListener listener = (TreeSelectionListener) ClassUtils.newInstance(className);
69 ((HtmlTree) parent).addTreeSelectionListener(listener);
70 }
71 else
72 {
73 throw new FacesException(
74 "Component is not HtmlTree children");
75 }
76 }
77 }
78 }