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