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    
031    import javax.faces.webapp.FacetTag;
032    import javax.servlet.jsp.JspException;
033    import javax.servlet.jsp.tagext.BodyTagSupport;
034    
035    /*
036     * Created by IntelliJ IDEA.
037     * User: bommel
038     * Date: 09.05.2006
039     * Time: 17:41:39
040     */
041    
042    /**
043     * Renders a submenu with select one items (like a radio button).
044     *
045     */
046    
047    @Tag(name = "menuRadio", tagExtraInfoClassName = "org.apache.myfaces.tobago.taglib.component.CommandTagExtraInfo")
048    @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.MenuRadioTag")
049    public class MenuRadioExtensionTag extends BodyTagSupport implements AbstractCommandTagDeclaration,
050        HasIdBindingAndRendered, HasLabel, IsDisabled, HasValue, HasConverter {
051    
052      private String rendered;
053      private String value;
054    
055      private MenuCommandTag menuCommandTag;
056      private SelectOneRadioTag selectOneRadio;
057      private FacetTag facetTag;
058      private String action;
059      private String actionListener;
060      private String onclick;
061      private String link;
062      private String disabled;
063      private String binding;
064      private String label;
065      private String immediate;
066      private String transition;
067      private String converter;
068    
069      @Override
070      public int doStartTag() throws JspException {
071    
072        menuCommandTag = new MenuCommandTag();
073        menuCommandTag.setPageContext(pageContext);
074        menuCommandTag.setParent(getParent());
075    
076        if (rendered != null) {
077          menuCommandTag.setRendered(rendered);
078        }
079        if (action != null) {
080          menuCommandTag.setAction(action);
081        }
082        if (actionListener != null) {
083          menuCommandTag.setActionListener(actionListener);
084        }
085        if (onclick != null) {
086          menuCommandTag.setOnclick(onclick);
087        }
088        if (link != null) {
089          menuCommandTag.setLink(link);
090        }
091        if (disabled != null) {
092          menuCommandTag.setDisabled(disabled);
093        }
094        if (binding != null) {
095          menuCommandTag.setBinding(binding);
096        }
097        if (label != null) {
098          menuCommandTag.setLabel(label);
099        }
100        if (immediate != null) {
101          menuCommandTag.setImmediate(immediate);
102        }
103        if (transition != null) {
104          menuCommandTag.setTransition(transition);
105        }
106        menuCommandTag.doStartTag();
107    
108        facetTag = new FacetTag();
109        facetTag.setPageContext(pageContext);
110        facetTag.setParent(menuCommandTag);
111        facetTag.setName(org.apache.myfaces.tobago.TobagoConstants.FACET_ITEMS);
112    
113        facetTag.doStartTag();
114        selectOneRadio = new SelectOneRadioTag();
115        selectOneRadio.setPageContext(pageContext);
116        selectOneRadio.setParent(facetTag);
117        if (converter != null) {
118          selectOneRadio.setConverter(converter);
119        }
120        if (value != null) {
121          selectOneRadio.setValue(value);
122        }
123        selectOneRadio.doStartTag();
124    
125        return super.doStartTag();
126      }
127    
128      @Override
129      public int doEndTag() throws JspException {
130        selectOneRadio.doEndTag();
131        facetTag.doEndTag();
132        menuCommandTag.doEndTag();
133    
134        return super.doEndTag();
135      }
136    
137      public void setAction(String action) {
138        this.action = action;
139      }
140    
141      public void setActionListener(String actionListener) {
142        this.actionListener = actionListener;
143      }
144    
145      public void setOnclick(String onclick) {
146        this.onclick = onclick;
147      }
148    
149      public void setLink(String navigate) {
150        this.link = navigate;
151      }
152    
153      public void setBinding(String binding) throws JspException {
154        this.binding = binding;
155      }
156    
157      public void setRendered(String rendered) {
158        this.rendered = rendered;
159      }
160    
161      public void setDisabled(String disabled) {
162        this.disabled = disabled;
163      }
164    
165      public void setValue(String value) {
166        this.value = value;
167      }
168    
169      public void setLabel(String label) {
170        this.label = label;
171      }
172    
173      public void setImmediate(String immediate) {
174        this.immediate = immediate;
175      }
176    
177      public void setTransition(String transition) {
178        this.transition = transition;
179      }
180    
181      public void setConverter(String converter) {
182        this.converter = converter;
183      }
184    
185      public void release() {
186        super.release();
187        rendered = null;
188        value = null;
189        action = null;
190        actionListener = null;
191        onclick = null;
192        link = null;
193        disabled = null;
194        binding = null;
195        label = null;
196        immediate = null;
197        transition = null;
198        converter = null;
199        menuCommandTag = null;
200        facetTag = null;
201        selectOneRadio = null;
202      }
203    
204    }