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