View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.taglib.extension;
21  
22  import org.apache.myfaces.tobago.apt.annotation.DynamicExpression;
23  import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
24  import org.apache.myfaces.tobago.apt.annotation.Tag;
25  import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
26  import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
27  import org.apache.myfaces.tobago.compat.FacesUtilsEL;
28  import org.apache.myfaces.tobago.internal.taglib.SelectBooleanCheckboxTag;
29  
30  import javax.el.ValueExpression;
31  import javax.servlet.jsp.JspException;
32  
33  /**
34   * Renders a checkbox.
35   */
36  @Tag(name = "selectBooleanCheckbox")
37  @ExtensionTag(
38      baseClassName = "org.apache.myfaces.tobago.internal.taglib.SelectBooleanCheckboxTag",
39      faceletHandler = "org.apache.myfaces.tobago.facelets.extension.SelectBooleanCheckboxExtensionHandler")
40  public class SelectBooleanCheckboxExtensionTag extends TobagoExtensionBodyTagSupport {
41  
42    private javax.el.ValueExpression value;
43    private javax.el.MethodExpression valueChangeListener;
44    private javax.el.ValueExpression disabled;
45    private javax.el.ValueExpression readonly;
46    private javax.el.ValueExpression onchange;
47    private javax.el.ValueExpression label;
48    private javax.el.ValueExpression itemLabel;
49    private javax.el.ValueExpression rendered;
50    private javax.el.ValueExpression binding;
51    private javax.el.ValueExpression tip;
52    private javax.el.ValueExpression converter;
53    private javax.el.MethodExpression validator;
54    private javax.el.ValueExpression labelWidth;
55    private javax.el.ValueExpression markup;
56    private javax.el.ValueExpression tabIndex;
57    private javax.el.ValueExpression required;
58    private javax.el.ValueExpression focus;
59    private javax.el.ValueExpression validatorMessage;
60    private javax.el.ValueExpression converterMessage;
61    private javax.el.ValueExpression requiredMessage;
62    private String fieldId;
63  
64    private LabelExtensionTag labelTag;
65    private SelectBooleanCheckboxTag selectBooleanCheckboxTag;
66  
67    @Override
68    public int doStartTag() throws JspException {
69  
70      labelTag = new LabelExtensionTag();
71      labelTag.setPageContext(pageContext);
72      if (id != null) {
73        labelTag.setId(id);
74      }
75      if (label != null) {
76        labelTag.setValue(label);
77      }
78      if (tip != null) {
79        labelTag.setTip(tip);
80      }
81      if (rendered != null) {
82        labelTag.setRendered(rendered);
83      }
84      if (labelWidth != null) {
85        labelTag.setColumns(createStringValueExpression(labelWidth.getExpressionString() + ";*"));
86      }
87      if (markup != null) {
88        labelTag.setMarkup(markup);
89      }
90      labelTag.setParent(getParent());
91      labelTag.setJspId(nextJspId());
92      labelTag.doStartTag();
93  
94      selectBooleanCheckboxTag = new SelectBooleanCheckboxTag();
95      selectBooleanCheckboxTag.setPageContext(pageContext);
96      if (value != null) {
97        selectBooleanCheckboxTag.setValue(value);
98      }
99      if (valueChangeListener != null) {
100       selectBooleanCheckboxTag.setValueChangeListener(valueChangeListener);
101     }
102     if (binding != null) {
103       selectBooleanCheckboxTag.setBinding(binding);
104     }
105     if (onchange != null) {
106       selectBooleanCheckboxTag.setOnchange(onchange);
107     }
108     if (validator != null) {
109       selectBooleanCheckboxTag.setValidator(validator);
110     }
111     if (converter != null) {
112       selectBooleanCheckboxTag.setConverter(converter);
113     }
114     if (disabled != null) {
115       selectBooleanCheckboxTag.setDisabled(disabled);
116     }
117     if (fieldId != null) {
118       selectBooleanCheckboxTag.setId(fieldId);
119     }
120     if (readonly != null) {
121       selectBooleanCheckboxTag.setReadonly(readonly);
122     }
123     if (focus != null) {
124       selectBooleanCheckboxTag.setFocus(focus);
125     }
126     if (required != null) {
127       selectBooleanCheckboxTag.setRequired(required);
128     }
129     if (label != null) {
130       selectBooleanCheckboxTag.setLabel(label);
131     }
132     if (itemLabel != null) {
133       selectBooleanCheckboxTag.setItemLabel(itemLabel);
134     } else {
135       selectBooleanCheckboxTag.setItemLabel(FacesUtilsEL.createValueExpression(""));
136     }
137     if (markup != null) {
138       selectBooleanCheckboxTag.setMarkup(markup);
139     }
140     if (tabIndex != null) {
141       selectBooleanCheckboxTag.setTabIndex(tabIndex);
142     }
143     if (validatorMessage != null) {
144       selectBooleanCheckboxTag.setValidatorMessage(validatorMessage);
145     }
146     if (converterMessage != null) {
147       selectBooleanCheckboxTag.setConverterMessage(converterMessage);
148     }
149     if (requiredMessage != null) {
150       selectBooleanCheckboxTag.setRequiredMessage(requiredMessage);
151     }
152     selectBooleanCheckboxTag.setParent(labelTag);
153     selectBooleanCheckboxTag.setJspId(nextJspId());
154     selectBooleanCheckboxTag.doStartTag();
155 
156     return super.doStartTag();
157   }
158 
159   @Override
160   public int doEndTag() throws JspException {
161     selectBooleanCheckboxTag.doEndTag();
162     labelTag.doEndTag();
163     return super.doEndTag();
164   }
165 
166   @Override
167   public void release() {
168     super.release();
169     binding = null;
170     onchange = null;
171     disabled = null;
172     label = null;
173     itemLabel = null;
174     labelWidth = null;
175     readonly = null;
176     rendered = null;
177     converter = null;
178     validator = null;
179     tip = null;
180     value = null;
181     valueChangeListener = null;
182     markup = null;
183     tabIndex = null;
184     focus = null;
185     required = null;
186     selectBooleanCheckboxTag = null;
187     labelTag = null;
188     validatorMessage = null;
189     converterMessage = null;
190     requiredMessage = null;
191     fieldId = null;
192   }
193 
194   /**
195    * The current value of this component.
196    */
197   @TagAttribute
198   @UIComponentTagAttribute(type = "java.lang.Boolean")
199   public void setValue(javax.el.ValueExpression value) {
200     this.value = value;
201   }
202 
203   /**
204    * MethodBinding representing a value change listener method
205    * that will be notified when a new value has been set for this input component.
206    * The expression must evaluate to a public method that takes a ValueChangeEvent
207    * parameter, with a return type of void.
208    *
209    * @param valueChangeListener
210    */
211   @TagAttribute
212   @UIComponentTagAttribute(
213           type = {},
214           expression = DynamicExpression.METHOD_EXPRESSION_REQUIRED,
215           methodSignature = "javax.faces.event.ValueChangeEvent")
216   public void setValueChangeListener(javax.el.MethodExpression valueChangeListener) {
217     this.valueChangeListener = valueChangeListener;
218   }
219 
220   /**
221    * Flag indicating that this element is disabled.
222    */
223   @TagAttribute()
224   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
225   public void setDisabled(javax.el.ValueExpression disabled) {
226     this.disabled = disabled;
227   }
228 
229   /**
230    * Flag indicating that this component will prohibit changes by the user.
231    */
232   @TagAttribute
233   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
234   public void setReadonly(javax.el.ValueExpression readonly) {
235     this.readonly = readonly;
236   }
237 
238   /**
239    * Clientside script function to add to this component's onchange handler.
240    */
241   @TagAttribute
242   @UIComponentTagAttribute()
243   public void setOnchange(javax.el.ValueExpression onchange) {
244     this.onchange = onchange;
245   }
246 
247   /**
248    * Text value to display as label.
249    * If text contains an underscore the next character is used as accesskey.
250    */
251   @TagAttribute
252   @UIComponentTagAttribute()
253   public void setLabel(javax.el.ValueExpression label) {
254     this.label = label;
255   }
256 
257   /**
258    * Label to be displayed to the user for this option. This label will displayed beneath the component like 
259    * the label of other check box components.
260    */
261   @TagAttribute
262   @UIComponentTagAttribute()
263   public void setItemLabel(ValueExpression itemLabel) {
264     this.itemLabel = itemLabel;
265   }
266 
267   /**
268    * A method binding EL expression,
269    * accepting FacesContext, UIComponent,
270    * and Object parameters, and returning void, that validates
271    * the component's local value.
272    */
273   @TagAttribute
274   @UIComponentTagAttribute(type = {},
275       expression = DynamicExpression.METHOD_EXPRESSION,
276       methodSignature = { "javax.faces.context.FacesContext", "javax.faces.component.UIComponent", "java.lang.Object" })
277   public void setValidator(javax.el.MethodExpression validator) {
278     this.validator = validator;
279   }
280 
281   /**
282    * An expression that specifies the Converter for this component.
283    * If the value binding expression is a String,
284    * the String is used as an ID to look up a Converter.
285    * If the value binding expression is a Converter,
286    * uses that instance as the converter.
287    * The value can either be a static value (ID case only)
288    * or an EL expression.
289    */
290   @TagAttribute
291   @UIComponentTagAttribute(type = "javax.faces.convert.Converter",
292       expression = DynamicExpression.VALUE_EXPRESSION)
293   public void setConverter(javax.el.ValueExpression converter) {
294     this.converter = converter;
295   }
296 
297   /**
298    * Flag indicating whether or not this component should be rendered
299    * (during Render Response Phase), or processed on any subsequent form submit.
300    */
301   @TagAttribute
302   @UIComponentTagAttribute(type = "boolean", defaultValue = "true")
303   public void setRendered(javax.el.ValueExpression rendered) {
304     this.rendered = rendered;
305   }
306 
307   /**
308    * The value binding expression linking this
309    * component to a property in a backing bean.
310    */
311   @TagAttribute
312   @UIComponentTagAttribute(type = "javax.faces.component.UIComponent")
313   public void setBinding(javax.el.ValueExpression binding) {
314     this.binding = binding;
315   }
316 
317   /**
318    * Text value to display as tooltip.
319    */
320   @TagAttribute
321   @UIComponentTagAttribute()
322   public void setTip(javax.el.ValueExpression tip) {
323     this.tip = tip;
324   }
325 
326   /**
327    * The width for the label component. Default: 'auto'.
328    * This value is used in the gridLayouts columns attribute.
329    * See gridLayout tag for valid values.
330    */
331   @TagAttribute
332   @UIComponentTagAttribute()
333   public void setLabelWidth(javax.el.ValueExpression labelWidth) {
334     this.labelWidth = labelWidth;
335   }
336 
337   /**
338    * Indicate markup of this component.
339    * Possible value is 'none'. But this can be overridden in the theme.
340    */
341   @TagAttribute
342   @UIComponentTagAttribute(defaultValue = "none", type = "java.lang.String[]")
343   public void setMarkup(javax.el.ValueExpression markup) {
344     this.markup = markup;
345   }
346 
347   @TagAttribute
348   @UIComponentTagAttribute(type = "java.lang.Integer")
349   public void setTabIndex(javax.el.ValueExpression tabIndex) {
350     this.tabIndex = tabIndex;
351   }
352 
353   /**
354    * Flag indicating this component should receive the focus.
355    */
356   @TagAttribute
357   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
358   public void setFocus(javax.el.ValueExpression focus) {
359     this.focus = focus;
360   }
361 
362   /**
363    * Flag indicating that a value is required.
364    * If the value is an empty string a
365    * ValidationError occurs and a Error Message is rendered.
366    */
367   @TagAttribute
368   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
369   public void setRequired(javax.el.ValueExpression required) {
370     this.required = required;
371   }
372 
373   /**
374    * An expression that specifies the validator message
375    */
376   @TagAttribute
377   @UIComponentTagAttribute()
378   public void setValidatorMessage(javax.el.ValueExpression validatorMessage) {
379     this.validatorMessage = validatorMessage;
380   }
381 
382   /**
383    * An expression that specifies the converter message
384    */
385   @TagAttribute
386   @UIComponentTagAttribute()
387   public void setConverterMessage(javax.el.ValueExpression converterMessage) {
388     this.converterMessage = converterMessage;
389   }
390 
391   /**
392    * An expression that specifies the required message
393    */
394   @TagAttribute
395   @UIComponentTagAttribute()
396   public void setRequiredMessage(javax.el.ValueExpression requiredMessage) {
397     this.requiredMessage = requiredMessage;
398   }
399 
400   /**
401    * The component identifier for the input field component inside of the container.
402    * This value must be unique within the closest parent component that is a naming container.
403    */
404   @TagAttribute(rtexprvalue = true)
405   @UIComponentTagAttribute
406   public void setFieldId(String fieldId) {
407     this.fieldId = fieldId;
408   }
409 
410   /**
411    * The component identifier for this component.
412    * This value must be unique within the closest parent component that is a naming container.
413    * For tx components the id will be set to the container (e. g. the panel).
414    * To set the id of the input field, you have to use the attribute "fieldId".
415    */
416   @TagAttribute(rtexprvalue = true)
417   @UIComponentTagAttribute
418   public void setId(String id) {
419     super.setId(id);
420   }
421 }