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