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