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.apt.annotation.ExtensionTag;
023    import org.apache.myfaces.tobago.apt.annotation.Tag;
024    import org.apache.myfaces.tobago.taglib.component.SelectOneChoiceTag;
025    import org.apache.myfaces.tobago.taglib.decl.HasBinding;
026    import org.apache.myfaces.tobago.taglib.decl.HasConverter;
027    import org.apache.myfaces.tobago.taglib.decl.HasId;
028    import org.apache.myfaces.tobago.taglib.decl.HasLabel;
029    import org.apache.myfaces.tobago.taglib.decl.HasLabelWidth;
030    import org.apache.myfaces.tobago.taglib.decl.HasOnchange;
031    import org.apache.myfaces.tobago.taglib.decl.HasTabIndex;
032    import org.apache.myfaces.tobago.taglib.decl.HasTip;
033    import org.apache.myfaces.tobago.taglib.decl.HasValidator;
034    import org.apache.myfaces.tobago.taglib.decl.HasValue;
035    import org.apache.myfaces.tobago.taglib.decl.HasValueChangeListener;
036    import org.apache.myfaces.tobago.taglib.decl.IsDisabled;
037    import org.apache.myfaces.tobago.taglib.decl.IsFocus;
038    import org.apache.myfaces.tobago.taglib.decl.IsInline;
039    import org.apache.myfaces.tobago.taglib.decl.IsReadonly;
040    import org.apache.myfaces.tobago.taglib.decl.IsRendered;
041    import org.apache.myfaces.tobago.taglib.decl.IsRequired;
042    import org.apache.myfaces.tobago.taglib.decl.HasMarkup;
043    
044    import javax.servlet.jsp.JspException;
045    import javax.servlet.jsp.tagext.BodyTagSupport;
046    
047    /**
048     * Render a single selection dropdown list with a label.
049     */
050    
051    @Tag(name = "selectOneChoice")
052    @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.SelectOneChoiceTag")
053    public class SelectOneChoiceExtensionTag
054        extends BodyTagSupport
055        implements HasId, HasValue, HasValueChangeListener, IsDisabled,
056        IsReadonly, HasOnchange, IsInline, HasLabel, HasLabelWidth, IsRequired,
057        IsRendered, IsFocus, HasBinding, HasTip, HasValidator, HasConverter, HasMarkup, HasTabIndex {
058    
059      private String required;
060      private String value;
061      private String valueChangeListener;
062      private String disabled;
063      private String readonly;
064      private String onchange;
065      private String inline;
066      private String label;
067      private String rendered;
068      private String binding;
069      private String tip;
070      private String validator;
071      private String converter;
072      private String labelWidth;
073      private String tabIndex;
074      private String focus;
075      private String markup;
076    
077      private LabelExtensionTag labelTag;
078      private SelectOneChoiceTag selectOneChoiceTag;
079    
080      @Override
081      public int doStartTag() throws JspException {
082    
083        labelTag = new LabelExtensionTag();
084        labelTag.setPageContext(pageContext);
085        if (label != null) {
086          labelTag.setValue(label);
087        }
088        if (tip != null) {
089          labelTag.setTip(tip);
090        }
091        if (rendered != null) {
092          labelTag.setRendered(rendered);
093        }
094        if (labelWidth != null) {
095          labelTag.setColumns(labelWidth + ";*");
096        }
097        if (markup != null) {
098          labelTag.setMarkup(markup);
099        }    
100        labelTag.setParent(getParent());
101        labelTag.doStartTag();
102    
103        selectOneChoiceTag = new SelectOneChoiceTag();
104        selectOneChoiceTag.setPageContext(pageContext);
105        if (value != null) {
106          selectOneChoiceTag.setValue(value);
107        }
108        if (valueChangeListener != null) {
109          selectOneChoiceTag.setValueChangeListener(valueChangeListener);
110        }
111        if (validator != null) {
112          selectOneChoiceTag.setValidator(validator);
113        }
114        if (converter != null) {
115          selectOneChoiceTag.setConverter(converter);
116        }
117        if (binding != null) {
118          selectOneChoiceTag.setBinding(binding);
119        }
120        if (onchange != null) {
121          selectOneChoiceTag.setOnchange(onchange);
122        }
123        if (disabled != null) {
124          selectOneChoiceTag.setDisabled(disabled);
125        }
126        if (markup != null) {
127          selectOneChoiceTag.setMarkup(markup);
128        }
129        if (inline != null) {
130          selectOneChoiceTag.setInline(inline);
131        }
132        if (focus != null) {
133          selectOneChoiceTag.setFocus(focus);
134        }
135        if (id != null) {
136          selectOneChoiceTag.setId(id);
137        }
138        if (readonly != null) {
139          selectOneChoiceTag.setReadonly(readonly);
140        }
141        if (required != null) {
142          selectOneChoiceTag.setRequired(required);
143        }
144        if (tabIndex != null) {
145          selectOneChoiceTag.setTabIndex(tabIndex);
146        }
147        selectOneChoiceTag.setParent(labelTag);
148        selectOneChoiceTag.doStartTag();
149    
150        return super.doStartTag();
151      }
152    
153      @Override
154      public int doEndTag() throws JspException {
155        selectOneChoiceTag.doEndTag();
156        labelTag.doEndTag();
157        return super.doEndTag();
158      }
159    
160      @Override
161      public void release() {
162        super.release();
163        binding = null;
164        onchange = null;
165        disabled = null;
166        inline = null;
167        label = null;
168        labelWidth = null;
169        converter = null;
170        validator = null;
171        readonly = null;
172        rendered = null;
173        required = null;
174        tip = null;
175        value = null;
176        valueChangeListener = null;
177        tabIndex = null;
178        selectOneChoiceTag = null;
179        labelTag = null;
180        focus = null;
181        markup = null;
182      }
183    
184      public void setRequired(String required) {
185        this.required = required;
186      }
187    
188      public void setValue(String value) {
189        this.value = value;
190      }
191    
192      public void setValueChangeListener(String valueChangeListener) {
193        this.valueChangeListener = valueChangeListener;
194      }
195    
196      public void setValidator(String validator) {
197        this.validator = validator;
198      }
199    
200      public void setDisabled(String disabled) {
201        this.disabled = disabled;
202      }
203    
204      public void setReadonly(String readonly) {
205        this.readonly = readonly;
206      }
207    
208      public void setOnchange(String onchange) {
209        this.onchange = onchange;
210      }
211    
212      public void setConverter(String converter) {
213        this.converter = converter;
214      }
215    
216      public void setInline(String inline) {
217        this.inline = inline;
218      }
219    
220      public void setLabel(String label) {
221        this.label = label;
222      }
223    
224      public void setRendered(String rendered) {
225        this.rendered = rendered;
226      }
227    
228      public void setBinding(String binding) {
229        this.binding = binding;
230      }
231    
232      public void setTip(String tip) {
233        this.tip = tip;
234      }
235    
236      public void setLabelWidth(String labelWidth) {
237        this.labelWidth = labelWidth;
238      }
239    
240      public void setTabIndex(String tabIndex) {
241        this.tabIndex = tabIndex;
242      }
243    
244      public void setFocus(String focus) {
245        this.focus = focus;
246      }
247    
248      public void setMarkup(String markup) {
249        this.markup = markup;
250      }
251    }