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