001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package org.apache.myfaces.tobago.taglib.extension;
021
022 import org.apache.myfaces.tobago.TobagoConstants;
023 import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
024 import org.apache.myfaces.tobago.apt.annotation.Tag;
025 import org.apache.myfaces.tobago.component.ComponentUtil;
026 import org.apache.myfaces.tobago.component.UICommand;
027 import org.apache.myfaces.tobago.taglib.component.AbstractCommandTagDeclaration;
028 import org.apache.myfaces.tobago.taglib.component.MenuCommandTag;
029 import org.apache.myfaces.tobago.taglib.component.SelectOneRadioTag;
030 import org.apache.myfaces.tobago.taglib.decl.HasConverter;
031 import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered;
032 import org.apache.myfaces.tobago.taglib.decl.HasLabel;
033 import org.apache.myfaces.tobago.taglib.decl.HasValue;
034 import org.apache.myfaces.tobago.taglib.decl.IsDisabled;
035
036 import javax.faces.component.UIComponent;
037 import javax.faces.el.ValueBinding;
038 import javax.faces.webapp.FacetTag;
039 import javax.servlet.jsp.JspException;
040 import javax.servlet.jsp.tagext.BodyTagSupport;
041
042 /*
043 * Date: 09.05.2006
044 * Time: 17:41:39
045 */
046
047 /**
048 * Renders a submenu with select one items (like a radio button).
049 */
050
051 @Tag(name = "menuRadio", tagExtraInfoClassName = "org.apache.myfaces.tobago.taglib.component.CommandTagExtraInfo")
052 @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.MenuRadioTag")
053 public class MenuRadioExtensionTag extends BodyTagSupport implements AbstractCommandTagDeclaration,
054 HasIdBindingAndRendered, HasLabel, IsDisabled, HasValue, HasConverter {
055
056 private String rendered;
057 private String value;
058
059 private MenuCommandTag menuCommandTag;
060 private SelectOneRadioTag selectOneRadio;
061 private FacetTag facetTag;
062 private String action;
063 private String actionListener;
064 private String onclick;
065 private String link;
066 private String resource;
067 private String jsfResource;
068 private String disabled;
069 private String binding;
070 private String label;
071 private String immediate;
072 private String transition;
073 private String converter;
074
075 @Override
076 public int doStartTag() throws JspException {
077
078 menuCommandTag = new MenuCommandTag();
079 menuCommandTag.setPageContext(pageContext);
080 menuCommandTag.setParent(getParent());
081
082 if (rendered != null) {
083 menuCommandTag.setRendered(rendered);
084 }
085 if (action != null) {
086 menuCommandTag.setAction(action);
087 }
088 if (actionListener != null) {
089 menuCommandTag.setActionListener(actionListener);
090 }
091 if (onclick != null) {
092 menuCommandTag.setOnclick(onclick);
093 }
094 if (link != null) {
095 menuCommandTag.setLink(link);
096 }
097 if (resource != null) {
098 menuCommandTag.setResource(resource);
099 }
100 if (jsfResource != null) {
101 menuCommandTag.setJsfResource(jsfResource);
102 }
103 if (disabled != null) {
104 menuCommandTag.setDisabled(disabled);
105 }
106 if (binding != null) {
107 menuCommandTag.setBinding(binding);
108 }
109 if (label != null) {
110 menuCommandTag.setLabel(label);
111 }
112 if (immediate != null) {
113 menuCommandTag.setImmediate(immediate);
114 }
115 if (transition != null) {
116 menuCommandTag.setTransition(transition);
117 }
118 menuCommandTag.doStartTag();
119
120 facetTag = new FacetTag();
121 facetTag.setPageContext(pageContext);
122 facetTag.setParent(menuCommandTag);
123 facetTag.setName(org.apache.myfaces.tobago.TobagoConstants.FACET_ITEMS);
124
125 facetTag.doStartTag();
126 selectOneRadio = new SelectOneRadioTag();
127 selectOneRadio.setPageContext(pageContext);
128 selectOneRadio.setParent(facetTag);
129 if (converter != null) {
130 selectOneRadio.setConverter(converter);
131 }
132 if (value != null) {
133 selectOneRadio.setValue(value);
134 }
135 selectOneRadio.doStartTag();
136
137 return super.doStartTag();
138 }
139
140 @Override
141 public int doEndTag() throws JspException {
142
143 // Move attribute renderedPartially from selectOne to menuCommand component
144 UIComponent selectOneComponent = selectOneRadio.getComponentInstance();
145 UICommand command = (UICommand) menuCommandTag.getComponentInstance();
146 ValueBinding binding = selectOneComponent.getValueBinding(TobagoConstants.ATTR_RENDERED_PARTIALLY);
147 if (binding != null) {
148 command.setValueBinding(TobagoConstants.ATTR_RENDERED_PARTIALLY, binding);
149 } else {
150 Object renderedPartially = selectOneComponent.getAttributes().get(TobagoConstants.ATTR_RENDERED_PARTIALLY);
151 ComponentUtil.setRenderedPartially(command, (String) renderedPartially);
152 }
153
154 selectOneRadio.doEndTag();
155 facetTag.doEndTag();
156 menuCommandTag.doEndTag();
157
158 return super.doEndTag();
159 }
160
161 public void setAction(String action) {
162 this.action = action;
163 }
164
165 public void setActionListener(String actionListener) {
166 this.actionListener = actionListener;
167 }
168
169 public void setOnclick(String onclick) {
170 this.onclick = onclick;
171 }
172
173 public void setLink(String navigate) {
174 this.link = navigate;
175 }
176
177 public void setResource(String resource) {
178 this.resource = resource;
179 }
180
181 public void setJsfResource(String jsfResource) {
182 this.jsfResource = jsfResource;
183 }
184
185 public void setBinding(String binding) throws JspException {
186 this.binding = binding;
187 }
188
189 public void setRendered(String rendered) {
190 this.rendered = rendered;
191 }
192
193 public void setDisabled(String disabled) {
194 this.disabled = disabled;
195 }
196
197 public void setValue(String value) {
198 this.value = value;
199 }
200
201 public void setLabel(String label) {
202 this.label = label;
203 }
204
205 public void setImmediate(String immediate) {
206 this.immediate = immediate;
207 }
208
209 public void setTransition(String transition) {
210 this.transition = transition;
211 }
212
213 public void setConverter(String converter) {
214 this.converter = converter;
215 }
216
217 @Override
218 public void release() {
219 super.release();
220 rendered = null;
221 value = null;
222 action = null;
223 actionListener = null;
224 onclick = null;
225 link = null;
226 resource = null;
227 jsfResource = null;
228 disabled = null;
229 binding = null;
230 label = null;
231 immediate = null;
232 transition = null;
233 converter = null;
234 menuCommandTag = null;
235 facetTag = null;
236 selectOneRadio = null;
237 }
238
239 }