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