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