View Javadoc

1   package org.apache.myfaces.tobago.taglib.extension12;
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.DynamicExpression;
21  import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
22  import org.apache.myfaces.tobago.apt.annotation.Tag;
23  import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
24  import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
25  import org.apache.myfaces.tobago.internal.taglib.SelectBooleanCheckboxTag;
26  
27  import javax.servlet.jsp.JspException;
28  
29  /*
30   * Date: Oct 7, 2006
31   * Time: 9:13:21 AM
32   */
33  /**
34   * Renders a checkbox.
35   */
36  @Tag(name = "selectBooleanCheckbox")
37  @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.internal.taglib.SelectBooleanCheckboxTag")
38  public class SelectBooleanCheckboxExtensionTag extends TobagoExtensionBodyTagSupport {
39  
40    private javax.el.ValueExpression value;
41    private javax.el.MethodExpression valueChangeListener;
42    private javax.el.ValueExpression disabled;
43    private javax.el.ValueExpression readonly;
44    private javax.el.ValueExpression onchange;
45    private javax.el.ValueExpression label;
46    private javax.el.ValueExpression rendered;
47    private javax.el.ValueExpression binding;
48    private javax.el.ValueExpression tip;
49    private javax.el.ValueExpression converter;
50    private javax.el.MethodExpression validator;
51    private javax.el.ValueExpression labelWidth;
52    private javax.el.ValueExpression markup;
53    private javax.el.ValueExpression tabIndex;
54    private javax.el.ValueExpression required;
55    private javax.el.ValueExpression focus;
56    private javax.el.ValueExpression validatorMessage;
57    private javax.el.ValueExpression converterMessage;
58    private javax.el.ValueExpression requiredMessage;
59  
60    private LabelExtensionTag labelTag;
61    private SelectBooleanCheckboxTag selectBooleanCheckboxTag;
62  
63    @Override
64    public int doStartTag() throws JspException {
65  
66      labelTag = new LabelExtensionTag();
67      labelTag.setPageContext(pageContext);
68      if (label != null) {
69        labelTag.setValue(label);
70      }
71      if (tip != null) {
72        labelTag.setTip(tip);
73      }
74      if (rendered != null) {
75        labelTag.setRendered(rendered);
76      }
77      if (labelWidth != null) {
78        labelTag.setColumns(createStringValueExpression(labelWidth.getExpressionString() + ";*"));
79      }
80      if (markup != null) {
81        labelTag.setMarkup(markup);
82      }
83      labelTag.setParent(getParent());
84      labelTag.doStartTag();
85  
86      selectBooleanCheckboxTag = new SelectBooleanCheckboxTag();
87      selectBooleanCheckboxTag.setPageContext(pageContext);
88      if (value != null) {
89        selectBooleanCheckboxTag.setValue(value);
90      }
91      if (valueChangeListener != null) {
92        selectBooleanCheckboxTag.setValueChangeListener(valueChangeListener);
93      }
94      if (binding != null) {
95        selectBooleanCheckboxTag.setBinding(binding);
96      }
97      if (onchange != null) {
98        selectBooleanCheckboxTag.setOnchange(onchange);
99      }
100     if (validator != null) {
101       selectBooleanCheckboxTag.setValidator(validator);
102     }
103     if (converter != null) {
104       selectBooleanCheckboxTag.setConverter(converter);
105     }
106     if (disabled != null) {
107       selectBooleanCheckboxTag.setDisabled(disabled);
108     }
109 
110     if (id != null) {
111       selectBooleanCheckboxTag.setId(id);
112     }
113 
114     if (readonly != null) {
115       selectBooleanCheckboxTag.setReadonly(readonly);
116     }
117 
118     if (focus != null) {
119       selectBooleanCheckboxTag.setFocus(focus);
120     }
121 
122     if (required != null) {
123       selectBooleanCheckboxTag.setRequired(required);
124     }
125     // TODO item Label
126     //if (itemLabel != null) {
127     //  selectOneRadioTag.setLabel(itemLabel);
128     //}
129 
130     if (markup != null) {
131       selectBooleanCheckboxTag.setMarkup(markup);
132     }
133     if (tabIndex != null) {
134       selectBooleanCheckboxTag.setTabIndex(tabIndex);
135     }
136     if (validatorMessage != null) {
137       selectBooleanCheckboxTag.setValidatorMessage(validatorMessage);
138     }
139     if (converterMessage != null) {
140       selectBooleanCheckboxTag.setConverterMessage(converterMessage);
141     }
142     if (requiredMessage != null) {
143       selectBooleanCheckboxTag.setRequiredMessage(requiredMessage);
144     }
145     selectBooleanCheckboxTag.setParent(labelTag);
146     selectBooleanCheckboxTag.doStartTag();
147 
148     return super.doStartTag();
149   }
150 
151   @Override
152   public int doEndTag() throws JspException {
153     selectBooleanCheckboxTag.doEndTag();
154     labelTag.doEndTag();
155     return super.doEndTag();
156   }
157 
158   @Override
159   public void release() {
160     super.release();
161     binding = null;
162     onchange = null;
163     disabled = null;
164     label = null;
165     labelWidth = null;
166     readonly = null;
167     rendered = null;
168     converter = null;
169     validator = null;
170     tip = null;
171     value = null;
172     valueChangeListener = null;
173     markup = null;
174     tabIndex = null;
175     focus = null;
176     required = null;
177     selectBooleanCheckboxTag = null;
178     labelTag = null;
179     validatorMessage = null;
180     converterMessage = null;
181     requiredMessage = null;
182   }
183 
184   /**
185    * The current value of this component.
186    */
187   @TagAttribute
188   @UIComponentTagAttribute(type = "java.lang.Boolean")
189   public void setValue(javax.el.ValueExpression value) {
190     this.value = value;
191   }
192 
193   /**
194    * MethodBinding representing a value change listener method
195    * that will be notified when a new value has been set for this input component.
196    * The expression must evaluate to a public method that takes a ValueChangeEvent
197    * parameter, with a return type of void.
198    *
199    * @param valueChangeListener
200    */
201   @TagAttribute
202   @UIComponentTagAttribute(
203           type = {},
204           expression = DynamicExpression.METHOD_BINDING_REQUIRED,
205           methodSignature = "javax.faces.event.ValueChangeEvent")
206   public void setValueChangeListener(javax.el.MethodExpression valueChangeListener) {
207     this.valueChangeListener = valueChangeListener;
208   }
209 
210   /**
211    * Flag indicating that this element is disabled.
212    */
213   @TagAttribute()
214   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "Boolean.FALSE")
215   public void setDisabled(javax.el.ValueExpression disabled) {
216     this.disabled = disabled;
217   }
218 
219   /**
220    * Flag indicating that this component will prohibit changes by the user.
221    */
222   @TagAttribute
223   @UIComponentTagAttribute(type = "java.lang.Boolean")
224   public void setReadonly(javax.el.ValueExpression readonly) {
225     this.readonly = readonly;
226   }
227 
228   /**
229    * Clientside script function to add to this component's onchange handler.
230    */
231   @TagAttribute
232   @UIComponentTagAttribute()
233   public void setOnchange(javax.el.ValueExpression onchange) {
234     this.onchange = onchange;
235   }
236 
237   /**
238    * Text value to display as label.
239    * If text contains an underscore the next character is used as accesskey.
240    */
241   @TagAttribute
242   @UIComponentTagAttribute()
243   public void setLabel(javax.el.ValueExpression label) {
244     this.label = label;
245   }
246 
247   /**
248    * A method binding EL expression,
249    * accepting FacesContext, UIComponent,
250    * and Object parameters, and returning void, that validates
251    * the component's local value.
252    */
253   @TagAttribute
254   @UIComponentTagAttribute(type = {},
255       expression = DynamicExpression.METHOD_BINDING,
256       methodSignature = { "javax.faces.context.FacesContext", "javax.faces.component.UIComponent", "java.lang.Object" })
257   public void setValidator(javax.el.MethodExpression validator) {
258     this.validator = validator;
259   }
260 
261   /**
262    * An expression that specifies the Converter for this component.
263    * If the value binding expression is a String,
264    * the String is used as an ID to look up a Converter.
265    * If the value binding expression is a Converter,
266    * uses that instance as the converter.
267    * The value can either be a static value (ID case only)
268    * or an EL expression.
269    */
270   @TagAttribute
271   @UIComponentTagAttribute(type = "javax.faces.convert.Converter",
272       expression = DynamicExpression.VALUE_BINDING)
273   public void setConverter(javax.el.ValueExpression converter) {
274     this.converter = converter;
275   }
276 
277   /**
278    * Flag indicating whether or not this component should be rendered
279    * (during Render Response Phase), or processed on any subsequent form submit.
280    */
281   @TagAttribute
282   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "Boolean.TRUE")
283   public void setRendered(javax.el.ValueExpression rendered) {
284     this.rendered = rendered;
285   }
286 
287   /**
288    * The value binding expression linking this
289    * component to a property in a backing bean.
290    */
291   @TagAttribute
292   @UIComponentTagAttribute(type = "javax.faces.component.UIComponent")
293   public void setBinding(javax.el.ValueExpression binding) {
294     this.binding = binding;
295   }
296 
297   /**
298    * Text value to display as tooltip.
299    */
300   @TagAttribute
301   @UIComponentTagAttribute()
302   public void setTip(javax.el.ValueExpression tip) {
303     this.tip = tip;
304   }
305 
306   /**
307    * The width for the label component. Default: 'fixed'.
308    * This value is used in the gridLayouts columns attribute.
309    * See gridLayout tag for valid values.
310    */
311   @TagAttribute
312   @UIComponentTagAttribute()
313   public void setLabelWidth(javax.el.ValueExpression labelWidth) {
314     this.labelWidth = labelWidth;
315   }
316 
317   /**
318    * Indicate markup of this component.
319    * Possible value is 'none'. But this can be overridden in the theme.
320    */
321   @TagAttribute
322   @UIComponentTagAttribute(defaultValue = "none", type = "java.lang.String[]")
323   public void setMarkup(javax.el.ValueExpression markup) {
324     this.markup = markup;
325   }
326 
327   @TagAttribute
328   @UIComponentTagAttribute(type = "java.lang.Integer")
329   public void setTabIndex(javax.el.ValueExpression tabIndex) {
330     this.tabIndex = tabIndex;
331   }
332 
333   /**
334    * Flag indicating this component should recieve the focus.
335    */
336   @TagAttribute
337   @UIComponentTagAttribute(type = "java.lang.Boolean")
338   public void setFocus(javax.el.ValueExpression focus) {
339     this.focus = focus;
340   }
341 
342   /**
343    * Flag indicating that a value is required.
344    * If the value is an empty string a
345    * ValidationError occurs and a Error Message is rendered.
346    */
347   @TagAttribute
348   @UIComponentTagAttribute(type = "java.lang.Boolean")
349   public void setRequired(javax.el.ValueExpression required) {
350     this.required = required;
351   }
352 
353   /**
354    * An expression that specifies the validator message
355    */
356   @TagAttribute
357   @UIComponentTagAttribute()
358   public void setValidatorMessage(javax.el.ValueExpression validatorMessage) {
359     this.validatorMessage = validatorMessage;
360   }
361 
362   /**
363    * An expression that specifies the converter message
364    */
365   @TagAttribute
366   @UIComponentTagAttribute()
367   public void setConverterMessage(javax.el.ValueExpression converterMessage) {
368     this.converterMessage = converterMessage;
369   }
370 
371   /**
372    * An expression that specifies the required message
373    */
374   @TagAttribute
375   @UIComponentTagAttribute()
376   public void setRequiredMessage(javax.el.ValueExpression requiredMessage) {
377     this.requiredMessage = requiredMessage;
378   }
379 
380 }