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