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    //import org.apache.myfaces.tobago.taglib.decl.IsRequired;
037    import org.apache.myfaces.tobago.taglib.decl.IsFocus;
038    
039    import javax.servlet.jsp.JspException;
040    import javax.servlet.jsp.tagext.BodyTagSupport;
041    
042    /*
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, //IsRequired
054        IsFocus {
055    
056      private String value;
057      private String valueChangeListener;
058      private String disabled;
059      private String readonly;
060      private String onchange;
061      private String label;
062      private String rendered;
063      private String binding;
064      private String tip;
065      private String converter;
066      private String validator;
067      private String labelWidth;
068      private String markup;
069      private String tabIndex;
070      //private String required;
071      private String focus;
072    
073      private LabelExtensionTag labelTag;
074      private SelectBooleanCheckboxTag selectBooleanCheckboxTag;
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        if (markup != null) {
094          labelTag.setMarkup(markup);
095        }
096        labelTag.setParent(getParent());
097        labelTag.doStartTag();
098    
099        selectBooleanCheckboxTag = new SelectBooleanCheckboxTag();
100        selectBooleanCheckboxTag.setPageContext(pageContext);
101        if (value != null) {
102          selectBooleanCheckboxTag.setValue(value);
103        }
104        if (valueChangeListener != null) {
105          selectBooleanCheckboxTag.setValueChangeListener(valueChangeListener);
106        }
107        if (binding != null) {
108          selectBooleanCheckboxTag.setBinding(binding);
109        }
110        if (onchange != null) {
111          selectBooleanCheckboxTag.setOnchange(onchange);
112        }
113        if (validator != null) {
114          selectBooleanCheckboxTag.setValidator(validator);
115        }
116        if (converter != null) {
117          selectBooleanCheckboxTag.setConverter(converter);
118        }
119        if (disabled != null) {
120          selectBooleanCheckboxTag.setDisabled(disabled);
121        }
122    
123        if (id != null) {
124          selectBooleanCheckboxTag.setId(id);
125        }
126    
127        if (readonly != null) {
128          selectBooleanCheckboxTag.setReadonly(readonly);
129        }
130    
131        if (focus != null) {
132          selectBooleanCheckboxTag.setFocus(focus);
133        }
134    
135        //if (required != null) {
136        //  selectBooleanCheckboxTag.setRequired(required);
137        //}
138        // TODO item Label
139        //if (itemLabel != null) {
140        //  selectOneRadioTag.setLabel(itemLabel);
141        //}
142    
143        if (markup != null) {
144          selectBooleanCheckboxTag.setMarkup(markup);
145        }
146        if (tabIndex != null) {
147          selectBooleanCheckboxTag.setTabIndex(tabIndex);
148        }
149        selectBooleanCheckboxTag.setParent(labelTag);
150        selectBooleanCheckboxTag.doStartTag();
151    
152        return super.doStartTag();
153      }
154    
155      @Override
156      public int doEndTag() throws JspException {
157        selectBooleanCheckboxTag.doEndTag();
158        labelTag.doEndTag();
159        return super.doEndTag();
160      }
161    
162      @Override
163      public void release() {
164        super.release();
165        binding = null;
166        onchange = null;
167        disabled = null;
168        label = null;
169        labelWidth = null;
170        readonly = null;
171        rendered = null;
172        converter = null;
173        validator = null;
174        tip = null;
175        value = null;
176        valueChangeListener = null;
177        markup = null;
178        tabIndex = null;
179        focus = null;
180        //required = null;
181        selectBooleanCheckboxTag = null;
182        labelTag = null;
183      }
184    
185      public void setValue(String value) {
186        this.value = value;
187      }
188    
189      public void setValueChangeListener(String valueChangeListener) {
190        this.valueChangeListener = valueChangeListener;
191      }
192    
193      public void setDisabled(String disabled) {
194        this.disabled = disabled;
195      }
196    
197      public void setReadonly(String readonly) {
198        this.readonly = readonly;
199      }
200    
201      public void setOnchange(String onchange) {
202        this.onchange = onchange;
203      }
204    
205      public void setLabel(String label) {
206        this.label = label;
207      }
208    
209      public void setValidator(String validator) {
210        this.validator = validator;
211      }
212    
213      public void setConverter(String converter) {
214        this.converter = converter;
215      }
216    
217      public void setRendered(String rendered) {
218        this.rendered = rendered;
219      }
220    
221      public void setBinding(String binding) {
222        this.binding = binding;
223      }
224    
225      public void setTip(String tip) {
226        this.tip = tip;
227      }
228    
229      public void setLabelWidth(String labelWidth) {
230        this.labelWidth = labelWidth;
231      }
232    
233      public void setMarkup(String markup) {
234        this.markup = markup;
235      }
236    
237      public void setTabIndex(String tabIndex) {
238        this.tabIndex = tabIndex;
239      }
240    
241      public void setFocus(String focus) {
242        this.focus = focus;
243      }
244    
245      //public void setRequired(String required) {
246      //  this.required = required;
247      //}
248    }