View Javadoc

1   package org.apache.myfaces.tobago.taglib.extension12;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  import org.apache.myfaces.tobago.apt.annotation.DynamicExpression;
21  import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
22  import org.apache.myfaces.tobago.apt.annotation.Tag;
23  import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
24  import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
25  import org.apache.myfaces.tobago.internal.taglib.TimeTag;
26  
27  import javax.servlet.jsp.JspException;
28  
29  /**
30   * Renders a time input field with a label.
31   * <br />
32   * Short syntax of:
33   * <p/>
34   * <pre>
35   * &lt;tc:panel>
36   *   &lt;f:facet name="layout">
37   *     &lt;tc:gridLayout columns="fixed;*"/>
38   *   &lt;/f:facet>
39   *   &lt;tc:label value="#{label}" for="@auto"/>
40   *   &lt;tc:time value="#{value}">
41   *     ...
42   *   &lt;/tc:in>
43   * &lt;/tc:panel>
44   * </pre>
45   */
46  @Tag(name = "time")
47  @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.internal.taglib.TimeTag")
48  public class TimeExtensionTag extends TobagoExtensionBodyTagSupport {
49  
50    private javax.el.ValueExpression binding;
51    private javax.el.ValueExpression converter;
52    private javax.el.MethodExpression validator;
53    private javax.el.ValueExpression disabled;
54    private javax.el.ValueExpression focus;
55    private javax.el.ValueExpression label;
56    private javax.el.ValueExpression readonly;
57    private javax.el.ValueExpression rendered;
58    private javax.el.ValueExpression required;
59    private javax.el.ValueExpression tip;
60    private javax.el.ValueExpression value;
61    private javax.el.MethodExpression valueChangeListener;
62    private javax.el.ValueExpression inline;
63    private javax.el.ValueExpression onchange;
64    private javax.el.ValueExpression labelWidth;
65    private javax.el.ValueExpression tabIndex;
66    private javax.el.ValueExpression validatorMessage;
67    private javax.el.ValueExpression converterMessage;
68    private javax.el.ValueExpression requiredMessage;
69  
70    private LabelExtensionTag labelTag;
71    private TimeTag timeTag;
72  
73    @Override
74    public int doStartTag() throws JspException {
75  
76      labelTag = new LabelExtensionTag();
77      labelTag.setPageContext(pageContext);
78      if (label != null) {
79        labelTag.setValue(label);
80      }
81      if (tip != null) {
82        labelTag.setTip(tip);
83      }
84      if (rendered != null) {
85        labelTag.setRendered(rendered);
86      }
87      if (labelWidth != null) {
88        labelTag.setColumns(createStringValueExpression(labelWidth.getExpressionString() + ";*"));
89      }
90      labelTag.setParent(getParent());
91      labelTag.doStartTag();
92  
93      timeTag = new TimeTag();
94      timeTag.setPageContext(pageContext);
95      if (value != null) {
96        timeTag.setValue(value);
97      }
98      if (valueChangeListener != null) {
99        timeTag.setValueChangeListener(valueChangeListener);
100     }
101     if (binding != null) {
102       timeTag.setBinding(binding);
103     }
104     /*if (converter != null) {
105       timeTag.setConverter(converter);
106     }*/
107     if (validator != null) {
108       timeTag.setValidator(validator);
109     }
110     if (onchange != null) {
111       timeTag.setOnchange(onchange);
112     }
113     if (disabled != null) {
114       timeTag.setDisabled(disabled);
115     }
116     if (focus != null) {
117       timeTag.setFocus(focus);
118     }
119     if (id != null) {
120       timeTag.setId(id);
121     }
122     if (inline != null) {
123       timeTag.setInline(inline);
124     }
125     if (readonly != null) {
126       timeTag.setReadonly(readonly);
127     }
128     if (required != null) {
129       timeTag.setRequired(required);
130     }
131     if (tabIndex != null) {
132       timeTag.setTabIndex(tabIndex);
133     }
134     if (validatorMessage != null) {
135       timeTag.setValidatorMessage(validatorMessage);
136     }
137     if (converterMessage != null) {
138       timeTag.setConverterMessage(converterMessage);
139     }
140     if (requiredMessage != null) {
141       timeTag.setRequiredMessage(requiredMessage);
142     }
143     timeTag.setParent(labelTag);
144     timeTag.doStartTag();
145 
146     return super.doStartTag();
147   }
148 
149   @Override
150   public int doEndTag() throws JspException {
151     timeTag.doEndTag();
152     labelTag.doEndTag();
153     return super.doEndTag();
154   }
155 
156   @Override
157   public void release() {
158     super.release();
159     binding = null;
160     converter = null;
161     validator = null;
162     disabled = null;
163     labelWidth = null;
164     focus = null;
165     label = null;
166     inline = null;
167     readonly = null;
168     rendered = null;
169     required = null;
170     tip = null;
171     value = null;
172     onchange = null;
173     valueChangeListener = null;
174     tabIndex = null;
175     timeTag = null;
176     labelTag = null;
177     validatorMessage = null;
178     converterMessage = null;
179     requiredMessage = null;
180   }
181 
182   /**
183    * The current value of this component.
184    */
185   @TagAttribute
186   @UIComponentTagAttribute(type = "java.lang.Object")
187   public void setValue(javax.el.ValueExpression value) {
188     this.value = value;
189   }
190 
191   /**
192    * MethodBinding representing a value change listener method
193    * that will be notified when a new value has been set for this input component.
194    * The expression must evaluate to a public method that takes a ValueChangeEvent
195    * parameter, with a return type of void.
196    *
197    * @param valueChangeListener
198    */
199   @TagAttribute
200   @UIComponentTagAttribute(
201           type = {},
202           expression = DynamicExpression.METHOD_BINDING_REQUIRED,
203           methodSignature = "javax.faces.event.ValueChangeEvent")
204   public void setValueChangeListener(javax.el.MethodExpression valueChangeListener) {
205     this.valueChangeListener = valueChangeListener;
206   }
207 
208   /**
209    * Text value to display as label.
210    * If text contains an underscore the next character is used as accesskey.
211    */
212   @TagAttribute
213   @UIComponentTagAttribute()
214   public void setLabel(javax.el.ValueExpression label) {
215     this.label = label;
216   }
217 
218   /**
219    * Flag indicating this component should recieve the focus.
220    */
221   @TagAttribute
222   @UIComponentTagAttribute(type = "java.lang.Boolean")
223   public void setFocus(javax.el.ValueExpression focus) {
224     this.focus = focus;
225   }
226 
227   /**
228    * The value binding expression linking this
229    * component to a property in a backing bean.
230    */
231   @TagAttribute
232   @UIComponentTagAttribute(type = "javax.faces.component.UIComponent")
233   public void setBinding(javax.el.ValueExpression binding) {
234     this.binding = binding;
235   }
236 
237   /**
238    * Flag indicating whether or not this component should be rendered
239    * (during Render Response Phase), or processed on any subsequent form submit.
240    */
241   @TagAttribute
242   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "Boolean.TRUE")
243   public void setRendered(javax.el.ValueExpression rendered) {
244     this.rendered = rendered;
245   }
246 
247   /**
248    * An expression that specifies the Converter for this component.
249    * If the value binding expression is a String,
250    * the String is used as an ID to look up a Converter.
251    * If the value binding expression is a Converter,
252    * uses that instance as the converter.
253    * The value can either be a static value (ID case only)
254    * or an EL expression.
255    */
256   @TagAttribute
257   @UIComponentTagAttribute(type = "javax.faces.convert.Converter",
258       expression = DynamicExpression.VALUE_BINDING)
259   public void setConverter(javax.el.ValueExpression converter) {
260     this.converter = converter;
261   }
262 
263   /**
264    * A method binding EL expression,
265    * accepting FacesContext, UIComponent,
266    * and Object parameters, and returning void, that validates
267    * the component's local value.
268    */
269   @TagAttribute
270   @UIComponentTagAttribute(type = {},
271       expression = DynamicExpression.METHOD_BINDING,
272       methodSignature = { "javax.faces.context.FacesContext", "javax.faces.component.UIComponent", "java.lang.Object" })
273   public void setValidator(javax.el.MethodExpression validator) {
274     this.validator = validator;
275   }
276 
277   /**
278    * Clientside script function to add to this component's onchange handler.
279    */
280   @TagAttribute
281   @UIComponentTagAttribute()
282   public void setOnchange(javax.el.ValueExpression onchange) {
283     this.onchange = onchange;
284   }
285 
286   /**
287    * Flag indicating this component should rendered as an inline element.
288    */
289   @TagAttribute
290   @UIComponentTagAttribute(type = "java.lang.Boolean")
291   public void setInline(javax.el.ValueExpression inline) {
292     this.inline = inline;
293   }
294 
295   /**
296    * Flag indicating that this component will prohibit changes by the user.
297    */
298   @TagAttribute
299   @UIComponentTagAttribute(type = "java.lang.Boolean")
300   public void setReadonly(javax.el.ValueExpression readonly) {
301     this.readonly = readonly;
302   }
303 
304   /**
305    * Flag indicating that this element is disabled.
306    */
307   @TagAttribute()
308   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "Boolean.FALSE")
309   public void setDisabled(javax.el.ValueExpression disabled) {
310     this.disabled = disabled;
311   }
312 
313   /**
314    * Flag indicating that a value is required.
315    * If the value is an empty string a
316    * ValidationError occurs and a Error Message is rendered.
317    */
318   @TagAttribute
319   @UIComponentTagAttribute(type = "java.lang.Boolean")
320   public void setRequired(javax.el.ValueExpression required) {
321     this.required = required;
322   }
323 
324   /**
325    * Text value to display as tooltip.
326    */
327   @TagAttribute
328   @UIComponentTagAttribute()
329   public void setTip(javax.el.ValueExpression tip) {
330     this.tip = tip;
331   }
332 
333   /**
334    * The width for the label component. Default: 'fixed'.
335    * This value is used in the gridLayouts columns attribute.
336    * See gridLayout tag for valid values.
337    */
338   @TagAttribute
339   @UIComponentTagAttribute()
340   public void setLabelWidth(javax.el.ValueExpression labelWidth) {
341     this.labelWidth = labelWidth;
342   }
343 
344   @TagAttribute
345   @UIComponentTagAttribute(type = "java.lang.Integer")
346   public void setTabIndex(javax.el.ValueExpression tabIndex) {
347     this.tabIndex = tabIndex;
348   }
349 
350   /**
351    * An expression that specifies the validator message
352    */
353   @TagAttribute
354   @UIComponentTagAttribute()
355   public void setValidatorMessage(javax.el.ValueExpression validatorMessage) {
356     this.validatorMessage = validatorMessage;
357   }
358 
359   /**
360    * An expression that specifies the converter message
361    */
362   @TagAttribute
363   @UIComponentTagAttribute()
364   public void setConverterMessage(javax.el.ValueExpression converterMessage) {
365     this.converterMessage = converterMessage;
366   }
367 
368   /**
369    * An expression that specifies the required message
370    */
371   @TagAttribute
372   @UIComponentTagAttribute()
373   public void setRequiredMessage(javax.el.ValueExpression requiredMessage) {
374     this.requiredMessage = requiredMessage;
375   }
376 
377 }