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