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.el.MethodExpression;
30  import javax.el.ValueExpression;
31  import javax.servlet.jsp.JspException;
32  
33  /**
34   * Renders a time input field with 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:time value="#{value}">
45   *     ...
46   *   &lt;/tc:in>
47   * &lt;/tc:panel>
48   * </pre>
49   */
50  @Tag(name = "time")
51  @ExtensionTag(
52      baseClassName = "org.apache.myfaces.tobago.internal.taglib.TimeTag",
53          faceletHandler = "org.apache.myfaces.tobago.facelets.extension.TimeExtensionHandler")
54  public class TimeExtensionTag extends TobagoExtensionBodyTagSupport {
55  
56    private ValueExpression binding;
57    private ValueExpression converter;
58    private MethodExpression validator;
59    private ValueExpression disabled;
60    private ValueExpression focus;
61    private ValueExpression label;
62    private ValueExpression accessKey;
63    private ValueExpression readonly;
64    private ValueExpression rendered;
65    private ValueExpression required;
66    private ValueExpression tip;
67    private ValueExpression value;
68    private MethodExpression valueChangeListener;
69    private ValueExpression onchange;
70    private ValueExpression markup;
71    private ValueExpression labelWidth;
72    private ValueExpression tabIndex;
73    private ValueExpression validatorMessage;
74    private ValueExpression converterMessage;
75    private ValueExpression requiredMessage;
76    private String fieldId;
77  
78    private LabelExtensionTag labelTag;
79    private TimeTag timeTag;
80  
81    @Override
82    public int doStartTag() throws JspException {
83  
84      labelTag = new LabelExtensionTag();
85      labelTag.setPageContext(pageContext);
86      if (id != null) {
87        labelTag.setId(id);
88      }
89      if (label != null) {
90        labelTag.setValue(label);
91      }
92      if (accessKey != null) {
93        labelTag.setAccessKey(accessKey);
94      }
95      if (tip != null) {
96        labelTag.setTip(tip);
97      }
98      if (rendered != null) {
99        labelTag.setRendered(rendered);
100     }
101     if (labelWidth != null) {
102       labelTag.setColumns(createStringValueExpression(labelWidth.getExpressionString() + ";*"));
103     }
104     if (markup != null) {
105       labelTag.setMarkup(markup);
106     }
107     labelTag.setParent(getParent());
108     labelTag.setJspId(nextJspId());
109     labelTag.doStartTag();
110 
111     timeTag = new TimeTag();
112     timeTag.setPageContext(pageContext);
113     if (value != null) {
114       timeTag.setValue(value);
115     }
116     if (valueChangeListener != null) {
117       timeTag.setValueChangeListener(valueChangeListener);
118     }
119     if (binding != null) {
120       timeTag.setBinding(binding);
121     }
122     /*if (converter != null) {
123       timeTag.setConverter(converter);
124     }*/
125     if (validator != null) {
126       timeTag.setValidator(validator);
127     }
128     if (onchange != null) {
129       timeTag.setOnchange(onchange);
130     }
131     if (disabled != null) {
132       timeTag.setDisabled(disabled);
133     }
134     if (focus != null) {
135       timeTag.setFocus(focus);
136     }
137     if (fieldId != null) {
138       timeTag.setId(fieldId);
139     }
140     if (label != null) {
141       timeTag.setLabel(label);
142     }
143     if (readonly != null) {
144       timeTag.setReadonly(readonly);
145     }
146     if (required != null) {
147       timeTag.setRequired(required);
148     }
149     if (markup != null) {
150       timeTag.setMarkup(markup);
151     }
152     if (tabIndex != null) {
153       timeTag.setTabIndex(tabIndex);
154     }
155     if (validatorMessage != null) {
156       timeTag.setValidatorMessage(validatorMessage);
157     }
158     if (converterMessage != null) {
159       timeTag.setConverterMessage(converterMessage);
160     }
161     if (requiredMessage != null) {
162       timeTag.setRequiredMessage(requiredMessage);
163     }
164     timeTag.setParent(labelTag);
165     timeTag.setJspId(nextJspId());
166     timeTag.doStartTag();
167 
168     return super.doStartTag();
169   }
170 
171   @Override
172   public int doEndTag() throws JspException {
173     timeTag.doEndTag();
174     labelTag.doEndTag();
175     return super.doEndTag();
176   }
177 
178   @Override
179   public void release() {
180     super.release();
181     binding = null;
182     converter = null;
183     validator = null;
184     disabled = null;
185     labelWidth = null;
186     focus = null;
187     label = null;
188     accessKey = null;
189     readonly = null;
190     rendered = null;
191     required = null;
192     tip = null;
193     value = null;
194     onchange = null;
195     valueChangeListener = null;
196     markup = null;
197     tabIndex = null;
198     timeTag = null;
199     labelTag = null;
200     validatorMessage = null;
201     converterMessage = null;
202     requiredMessage = null;
203     fieldId = null;
204   }
205 
206   /**
207    * Indicate markup of this component.
208    * Possible value is 'none'. But this can be overridden in the theme.
209    */
210   @TagAttribute
211   @UIComponentTagAttribute(defaultValue = "none", type = "java.lang.String[]")
212   public void setMarkup(final ValueExpression markup) {
213     this.markup = markup;
214   }
215 
216   /**
217    * The current value of this component.
218    */
219   @TagAttribute
220   @UIComponentTagAttribute(type = "java.lang.Object")
221   public void setValue(final ValueExpression value) {
222     this.value = value;
223   }
224 
225   /**
226    * MethodBinding representing a value change listener method
227    * that will be notified when a new value has been set for this input component.
228    * The expression must evaluate to a public method that takes a ValueChangeEvent
229    * parameter, with a return type of void.
230    *
231    * @param valueChangeListener
232    */
233   @TagAttribute
234   @UIComponentTagAttribute(
235           type = {},
236           expression = DynamicExpression.METHOD_EXPRESSION_REQUIRED,
237           methodSignature = "javax.faces.event.ValueChangeEvent")
238   public void setValueChangeListener(final MethodExpression valueChangeListener) {
239     this.valueChangeListener = valueChangeListener;
240   }
241 
242   /**
243    * Text value to display as label.
244    * If text contains an underscore the next character is used as accesskey.
245    */
246   @TagAttribute
247   @UIComponentTagAttribute()
248   public void setLabel(final ValueExpression label) {
249     this.label = label;
250   }
251 
252   /**
253    * The accessKey of this component.
254    */
255   @TagAttribute
256   @UIComponentTagAttribute(type = "java.lang.Character")
257   public void setAccessKey(final javax.el.ValueExpression accessKey) {
258     this.accessKey = accessKey;
259   }
260 
261   /**
262    * Flag indicating this component should receive the focus.
263    */
264   @TagAttribute
265   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
266   public void setFocus(final ValueExpression focus) {
267     this.focus = focus;
268   }
269 
270   /**
271    * The value binding expression linking this
272    * component to a property in a backing bean.
273    */
274   @TagAttribute
275   @UIComponentTagAttribute(type = "javax.faces.component.UIComponent")
276   public void setBinding(final ValueExpression binding) {
277     this.binding = binding;
278   }
279 
280   /**
281    * Flag indicating whether or not this component should be rendered
282    * (during Render Response Phase), or processed on any subsequent form submit.
283    */
284   @TagAttribute
285   @UIComponentTagAttribute(type = "boolean", defaultValue = "true")
286   public void setRendered(final ValueExpression rendered) {
287     this.rendered = rendered;
288   }
289 
290   /**
291    * An expression that specifies the Converter for this component.
292    * If the value binding expression is a String,
293    * the String is used as an ID to look up a Converter.
294    * If the value binding expression is a Converter,
295    * uses that instance as the converter.
296    * The value can either be a static value (ID case only)
297    * or an EL expression.
298    */
299   @TagAttribute
300   @UIComponentTagAttribute(type = "javax.faces.convert.Converter",
301       expression = DynamicExpression.VALUE_EXPRESSION)
302   public void setConverter(final ValueExpression converter) {
303     this.converter = converter;
304   }
305 
306   /**
307    * A method binding EL expression,
308    * accepting FacesContext, UIComponent,
309    * and Object parameters, and returning void, that validates
310    * the component's local value.
311    */
312   @TagAttribute
313   @UIComponentTagAttribute(type = {},
314       expression = DynamicExpression.METHOD_EXPRESSION,
315       methodSignature = { "javax.faces.context.FacesContext", "javax.faces.component.UIComponent", "java.lang.Object" })
316   public void setValidator(final MethodExpression validator) {
317     this.validator = validator;
318   }
319 
320   /**
321    * Clientside script function to add to this component's onchange handler.
322    */
323   @TagAttribute
324   @UIComponentTagAttribute()
325   public void setOnchange(final ValueExpression onchange) {
326     this.onchange = onchange;
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(final 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(final 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(final 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(final 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(final ValueExpression labelWidth) {
375     this.labelWidth = labelWidth;
376   }
377 
378   @TagAttribute
379   @UIComponentTagAttribute(type = "java.lang.Integer")
380   public void setTabIndex(final 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(final 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(final 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(final 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(final 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(final String id) {
430     super.setId(id);
431   }
432 }