View Javadoc

1   package org.apache.myfaces.tobago.taglib.extension;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
21  import org.apache.myfaces.tobago.apt.annotation.Tag;
22  import org.apache.myfaces.tobago.internal.taglib.SelectBooleanCheckboxTag;
23  import org.apache.myfaces.tobago.taglib.decl.HasBooleanValue;
24  import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered;
25  import org.apache.myfaces.tobago.taglib.decl.HasLabel;
26  import org.apache.myfaces.tobago.taglib.decl.HasLabelWidth;
27  import org.apache.myfaces.tobago.taglib.decl.HasMarkup;
28  import org.apache.myfaces.tobago.taglib.decl.HasOnchange;
29  import org.apache.myfaces.tobago.taglib.decl.HasTabIndex;
30  import org.apache.myfaces.tobago.taglib.decl.HasTip;
31  import org.apache.myfaces.tobago.taglib.decl.HasValidator;
32  import org.apache.myfaces.tobago.taglib.decl.HasValueChangeListener;
33  import org.apache.myfaces.tobago.taglib.decl.IsDisabled;
34  import org.apache.myfaces.tobago.taglib.decl.IsFocus;
35  import org.apache.myfaces.tobago.taglib.decl.IsReadonly;
36  import org.apache.myfaces.tobago.taglib.decl.IsRequired;
37  import org.apache.myfaces.tobago.taglib.decl.HasValidatorMessage;
38  import org.apache.myfaces.tobago.taglib.decl.HasRequiredMessage;
39  import org.apache.myfaces.tobago.taglib.decl.HasConverterMessage;
40  
41  import javax.servlet.jsp.JspException;
42  import javax.servlet.jsp.tagext.BodyTagSupport;
43  
44  /*
45   * Date: Oct 7, 2006
46   * Time: 9:13:21 AM
47   */
48  /**
49   * Renders a checkbox.
50   */
51  @Tag(name = "selectBooleanCheckbox")
52  @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.internal.taglib.SelectBooleanCheckboxTag")
53  public class SelectBooleanCheckboxExtensionTag extends BodyTagSupport implements
54      HasValidator, HasOnchange, HasValueChangeListener, HasIdBindingAndRendered, HasLabel,
55      HasValidatorMessage, HasRequiredMessage, HasConverterMessage,
56      HasBooleanValue, HasLabelWidth, IsDisabled, HasTip, IsReadonly, HasMarkup, HasTabIndex, IsRequired,
57      IsFocus {
58  
59    private String value;
60    private String valueChangeListener;
61    private String disabled;
62    private String readonly;
63    private String onchange;
64    private String label;
65    private String rendered;
66    private String binding;
67    private String tip;
68    private String converter;
69    private String validator;
70    private String labelWidth;
71    private String markup;
72    private String tabIndex;
73    private String required;
74    private String focus;
75    private String validatorMessage;
76    private String converterMessage;
77    private String requiredMessage;
78  
79    private LabelExtensionTag labelTag;
80    private SelectBooleanCheckboxTag selectBooleanCheckboxTag;
81  
82    @Override
83    public int doStartTag() throws JspException {
84  
85      labelTag = new LabelExtensionTag();
86      labelTag.setPageContext(pageContext);
87      if (label != null) {
88        labelTag.setValue(label);
89      }
90      if (tip != null) {
91        labelTag.setTip(tip);
92      }
93      if (rendered != null) {
94        labelTag.setRendered(rendered);
95      }
96      if (labelWidth != null) {
97        labelTag.setColumns(labelWidth + ";*");
98      }
99      if (markup != null) {
100       labelTag.setMarkup(markup);
101     }
102     labelTag.setParent(getParent());
103     labelTag.doStartTag();
104 
105     selectBooleanCheckboxTag = new SelectBooleanCheckboxTag();
106     selectBooleanCheckboxTag.setPageContext(pageContext);
107     if (value != null) {
108       selectBooleanCheckboxTag.setValue(value);
109     }
110     if (valueChangeListener != null) {
111       selectBooleanCheckboxTag.setValueChangeListener(valueChangeListener);
112     }
113     if (binding != null) {
114       selectBooleanCheckboxTag.setBinding(binding);
115     }
116     if (onchange != null) {
117       selectBooleanCheckboxTag.setOnchange(onchange);
118     }
119     if (validator != null) {
120       selectBooleanCheckboxTag.setValidator(validator);
121     }
122     if (converter != null) {
123       selectBooleanCheckboxTag.setConverter(converter);
124     }
125     if (disabled != null) {
126       selectBooleanCheckboxTag.setDisabled(disabled);
127     }
128 
129     if (id != null) {
130       selectBooleanCheckboxTag.setId(id);
131     }
132 
133     if (readonly != null) {
134       selectBooleanCheckboxTag.setReadonly(readonly);
135     }
136 
137     if (focus != null) {
138       selectBooleanCheckboxTag.setFocus(focus);
139     }
140 
141     if (required != null) {
142       selectBooleanCheckboxTag.setRequired(required);
143     }
144     // TODO item Label
145     //if (itemLabel != null) {
146     //  selectOneRadioTag.setLabel(itemLabel);
147     //}
148 
149     if (markup != null) {
150       selectBooleanCheckboxTag.setMarkup(markup);
151     }
152     if (tabIndex != null) {
153       selectBooleanCheckboxTag.setTabIndex(tabIndex);
154     }
155     if (validatorMessage != null) {
156       selectBooleanCheckboxTag.setValidatorMessage(validatorMessage);
157     }
158     if (converterMessage != null) {
159       selectBooleanCheckboxTag.setConverterMessage(converterMessage);
160     }
161     if (requiredMessage != null) {
162       selectBooleanCheckboxTag.setRequiredMessage(requiredMessage);
163     }
164     selectBooleanCheckboxTag.setParent(labelTag);
165     selectBooleanCheckboxTag.doStartTag();
166 
167     return super.doStartTag();
168   }
169 
170   @Override
171   public int doEndTag() throws JspException {
172     selectBooleanCheckboxTag.doEndTag();
173     labelTag.doEndTag();
174     return super.doEndTag();
175   }
176 
177   @Override
178   public void release() {
179     super.release();
180     binding = null;
181     onchange = null;
182     disabled = null;
183     label = null;
184     labelWidth = null;
185     readonly = null;
186     rendered = null;
187     converter = null;
188     validator = null;
189     tip = null;
190     value = null;
191     valueChangeListener = null;
192     markup = null;
193     tabIndex = null;
194     focus = null;
195     required = null;
196     selectBooleanCheckboxTag = null;
197     labelTag = null;
198     validatorMessage = null;
199     converterMessage = null;
200     requiredMessage = null;
201   }
202 
203   public void setValue(String value) {
204     this.value = value;
205   }
206 
207   public void setValueChangeListener(String valueChangeListener) {
208     this.valueChangeListener = valueChangeListener;
209   }
210 
211   public void setDisabled(String disabled) {
212     this.disabled = disabled;
213   }
214 
215   public void setReadonly(String readonly) {
216     this.readonly = readonly;
217   }
218 
219   public void setOnchange(String onchange) {
220     this.onchange = onchange;
221   }
222 
223   public void setLabel(String label) {
224     this.label = label;
225   }
226 
227   public void setValidator(String validator) {
228     this.validator = validator;
229   }
230 
231   public void setConverter(String converter) {
232     this.converter = converter;
233   }
234 
235   public void setRendered(String rendered) {
236     this.rendered = rendered;
237   }
238 
239   public void setBinding(String binding) {
240     this.binding = binding;
241   }
242 
243   public void setTip(String tip) {
244     this.tip = tip;
245   }
246 
247   public void setLabelWidth(String labelWidth) {
248     this.labelWidth = labelWidth;
249   }
250 
251   public void setMarkup(String markup) {
252     this.markup = markup;
253   }
254 
255   public void setTabIndex(String tabIndex) {
256     this.tabIndex = tabIndex;
257   }
258 
259   public void setFocus(String focus) {
260     this.focus = focus;
261   }
262 
263   public void setRequired(String required) {
264     this.required = required;
265   }
266 
267   public void setValidatorMessage(String validatorMessage) {
268     this.validatorMessage = validatorMessage;
269   }
270 
271   public void setConverterMessage(String converterMessage) {
272     this.converterMessage = converterMessage;
273   }
274 
275   public void setRequiredMessage(String requiredMessage) {
276     this.requiredMessage = requiredMessage;
277   }
278 }