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 javax.el.ValueExpression;
22 import javax.faces.component.UIComponent;
23 import javax.faces.context.FacesContext;
24 import javax.servlet.jsp.JspException;
25
26 import org.apache.myfaces.custom.tree.HtmlTree;
27 import org.apache.myfaces.custom.tree.model.DefaultTreeModel;
28 import org.apache.myfaces.custom.tree.model.TreeModel;
29 import org.apache.myfaces.custom.tree.model.TreePath;
30 import org.apache.myfaces.shared_tomahawk.taglib.html.HtmlPanelGroupTag;
31
32
33
34
35
36
37
38
39
40 public class AbstractTreeTag extends HtmlPanelGroupTag {
41
42 private ValueExpression value;
43
44 private boolean expandRoot;
45
46 public String getComponentType() {
47 return "org.apache.myfaces.HtmlTree";
48 }
49
50 public String getRendererType() {
51 return "org.apache.myfaces.HtmlTree";
52 }
53
54 public ValueExpression getValue() {
55 return value;
56 }
57
58 public void setValue(ValueExpression newValue) {
59 value = newValue;
60 }
61
62 public boolean isExpandRoot() {
63 return expandRoot;
64 }
65
66 public void setExpandRoot(boolean expandRoot) {
67 this.expandRoot = expandRoot;
68 }
69
70
71
72
73 public int doStartTag() throws JspException {
74 FacesContext context = FacesContext.getCurrentInstance();
75
76 if (value != null) {
77 TreeModel treeModel = (TreeModel) (value.getValue(context.getELContext()));
78
79 if (treeModel == null) {
80
81 treeModel = new DefaultTreeModel();
82 value.setValue(context.getELContext(), treeModel);
83 }
84 }
85 int answer = super.doStartTag();
86 HtmlTree tree = (HtmlTree) getComponentInstance();
87
88 if (getCreated() && expandRoot) {
89
90 TreeModel model = tree.getModel(context);
91
92 if (model != null) {
93 tree.expandPath(new TreePath(new Object[] { model.getRoot() }),
94 context);
95 }
96 }
97
98 tree.addToModelListeners();
99 return answer;
100 }
101
102 public void release() {
103 super.release();
104 value = null;
105 expandRoot = false;
106 }
107
108
109
110
111 protected void setProperties(UIComponent component) {
112 super.setProperties(component);
113 FacesContext context = FacesContext.getCurrentInstance();
114
115
116 if (value != null) {
117 if (!value.isLiteralText()) {
118 component.setValueExpression("model", value);
119 }
120 } else {
121 ValueExpression binding = component.getValueExpression("model");
122 if (binding == null) {
123 binding = context.getApplication().
124 getExpressionFactory().createValueExpression(
125 context.getELContext(),"#{sessionScope.tree}", Object.class);
126 }
127 component.setValueExpression("model", binding);
128 }
129 }
130 }