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