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