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