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