1 package org.apache.myfaces.tobago.taglib.extension;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
22 import org.apache.myfaces.tobago.apt.annotation.Tag;
23 import static org.apache.myfaces.tobago.component.Attributes.RENDERED_PARTIALLY;
24 import org.apache.myfaces.tobago.component.Facets;
25 import org.apache.myfaces.tobago.component.UICommandBase;
26 import org.apache.myfaces.tobago.internal.taglib.MenuItemTag;
27 import org.apache.myfaces.tobago.internal.taglib.SelectBooleanCheckboxTag;
28 import org.apache.myfaces.tobago.taglib.decl.AbstractCommandTagDeclaration;
29 import org.apache.myfaces.tobago.taglib.decl.HasBooleanValue;
30 import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered;
31 import org.apache.myfaces.tobago.taglib.decl.HasLabel;
32 import org.apache.myfaces.tobago.taglib.decl.IsDisabled;
33
34 import javax.faces.component.UIComponent;
35 import javax.faces.el.ValueBinding;
36 import javax.faces.webapp.FacetTag;
37 import javax.servlet.jsp.JspException;
38 import javax.servlet.jsp.tagext.BodyTagSupport;
39
40
41
42
43
44
45
46
47
48
49 @Tag(name = "menuCheckbox", tagExtraInfoClassName = "org.apache.myfaces.tobago.taglib.component.CommandTagExtraInfo")
50 @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.MenuCheckboxTag")
51 public class MenuCheckboxExtensionTag extends BodyTagSupport implements AbstractCommandTagDeclaration,
52 HasIdBindingAndRendered, IsDisabled, HasBooleanValue, HasLabel {
53 private String rendered;
54 private String value;
55
56 private MenuItemTag menuCommandTag;
57 private SelectBooleanCheckboxTag selectBooleanCheckbox;
58 private FacetTag facetTag;
59 private String action;
60 private String actionListener;
61 private String onclick;
62 private String link;
63 private String resource;
64 private String jsfResource;
65 private String disabled;
66 private String binding;
67 private String label;
68 private String immediate;
69 private String target;
70 private String transition;
71 private String renderedPartially;
72
73 @Override
74 public int doStartTag() throws JspException {
75
76 menuCommandTag = new MenuItemTag();
77 menuCommandTag.setPageContext(pageContext);
78 menuCommandTag.setParent(getParent());
79
80 if (rendered != null) {
81 menuCommandTag.setRendered(rendered);
82 }
83 if (action != null) {
84 menuCommandTag.setAction(action);
85 }
86 if (actionListener != null) {
87 menuCommandTag.setActionListener(actionListener);
88 }
89 if (onclick != null) {
90 menuCommandTag.setOnclick(onclick);
91 }
92 if (link != null) {
93 menuCommandTag.setLink(link);
94 }
95 if (resource != null) {
96 menuCommandTag.setResource(resource);
97 }
98 if (jsfResource != null) {
99 menuCommandTag.setJsfResource(jsfResource);
100 }
101 if (disabled != null) {
102 menuCommandTag.setDisabled(disabled);
103 }
104 if (binding != null) {
105 menuCommandTag.setBinding(binding);
106 }
107 if (label != null) {
108 menuCommandTag.setLabel(label);
109 }
110 if (immediate != null) {
111 menuCommandTag.setImmediate(immediate);
112 }
113 if (target != null) {
114 menuCommandTag.setTarget(target);
115 }
116 if (transition != null) {
117 menuCommandTag.setTransition(transition);
118 }
119 if (renderedPartially != null) {
120 menuCommandTag.setRenderedPartially(renderedPartially);
121 }
122 menuCommandTag.doStartTag();
123
124 facetTag = new FacetTag();
125 facetTag.setPageContext(pageContext);
126 facetTag.setParent(menuCommandTag);
127 facetTag.setName(Facets.ITEMS);
128
129 facetTag.doStartTag();
130 selectBooleanCheckbox = new SelectBooleanCheckboxTag();
131 selectBooleanCheckbox.setPageContext(pageContext);
132 if (value != null) {
133 selectBooleanCheckbox.setValue(value);
134 }
135 selectBooleanCheckbox.setParent(facetTag);
136 selectBooleanCheckbox.doStartTag();
137 return super.doStartTag();
138 }
139
140 @Override
141 public int doEndTag() throws JspException {
142
143 if (renderedPartially == null) {
144
145 UIComponent selectBooleanComponent = selectBooleanCheckbox.getComponentInstance();
146 UICommandBase command = (UICommandBase) menuCommandTag.getComponentInstance();
147 ValueBinding binding = selectBooleanComponent.getValueBinding(RENDERED_PARTIALLY);
148 if (binding != null) {
149 command.setValueBinding(RENDERED_PARTIALLY, binding);
150 } else {
151 Object renderedPartially = selectBooleanComponent.getAttributes().get(RENDERED_PARTIALLY);
152 command.setRenderedPartially(StringUtils.split((String) renderedPartially, ", "));
153 }
154 }
155
156 selectBooleanCheckbox.doEndTag();
157 facetTag.doEndTag();
158 menuCommandTag.doEndTag();
159 return super.doEndTag();
160 }
161
162 public void setAction(String action) {
163 this.action = action;
164 }
165
166 public void setActionListener(String actionListener) {
167 this.actionListener = actionListener;
168 }
169
170 public void setOnclick(String onclick) {
171 this.onclick = onclick;
172 }
173
174 public void setLink(String navigate) {
175 this.link = navigate;
176 }
177
178 public void setResource(String resource) {
179 this.resource = resource;
180 }
181
182 public void setJsfResource(String jsfResource) {
183 this.jsfResource = jsfResource;
184 }
185
186 public void setBinding(String binding) throws JspException {
187 this.binding = binding;
188 }
189
190 public void setRendered(String rendered) {
191 this.rendered = rendered;
192 }
193
194 public void setDisabled(String disabled) {
195 this.disabled = disabled;
196 }
197
198 public void setValue(String value) {
199 this.value = value;
200 }
201
202 public void setLabel(String label) {
203 this.label = label;
204 }
205
206 public void setImmediate(String immediate) {
207 this.immediate = immediate;
208 }
209
210 public void setTarget(String target) {
211 this.target = target;
212 }
213
214 public void setTransition(String transition) {
215 this.transition = transition;
216 }
217
218 public void setRenderedPartially(String renderedPartially) {
219 this.renderedPartially = renderedPartially;
220 }
221
222 public void release() {
223 super.release();
224 rendered = null;
225 value = null;
226 action = null;
227 actionListener = null;
228 onclick = null;
229 link = null;
230 resource = null;
231 jsfResource = null;
232 disabled = null;
233 binding = null;
234 label = null;
235 immediate = null;
236 target = null;
237 transition = null;
238 renderedPartially = null;
239 menuCommandTag = null;
240 facetTag = null;
241 selectBooleanCheckbox = null;
242 }
243
244 }