View Javadoc

1   package org.apache.myfaces.tobago.taglib.extension;
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.ExtensionTag;
21  import org.apache.myfaces.tobago.apt.annotation.Tag;
22  import org.apache.myfaces.tobago.internal.taglib.TimeTag;
23  import org.apache.myfaces.tobago.taglib.decl.HasConverter;
24  import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered;
25  import org.apache.myfaces.tobago.taglib.decl.HasLabel;
26  import org.apache.myfaces.tobago.taglib.decl.HasLabelWidth;
27  import org.apache.myfaces.tobago.taglib.decl.HasOnchange;
28  import org.apache.myfaces.tobago.taglib.decl.HasTabIndex;
29  import org.apache.myfaces.tobago.taglib.decl.HasTip;
30  import org.apache.myfaces.tobago.taglib.decl.HasValidator;
31  import org.apache.myfaces.tobago.taglib.decl.HasValue;
32  import org.apache.myfaces.tobago.taglib.decl.HasValueChangeListener;
33  import org.apache.myfaces.tobago.taglib.decl.IsDisabled;
34  import org.apache.myfaces.tobago.taglib.decl.IsFocus;
35  import org.apache.myfaces.tobago.taglib.decl.IsInline;
36  import org.apache.myfaces.tobago.taglib.decl.IsReadonly;
37  import org.apache.myfaces.tobago.taglib.decl.IsRequired;
38  import org.apache.myfaces.tobago.taglib.decl.HasValidatorMessage;
39  import org.apache.myfaces.tobago.taglib.decl.HasRequiredMessage;
40  import org.apache.myfaces.tobago.taglib.decl.HasConverterMessage;
41  
42  import javax.servlet.jsp.JspException;
43  import javax.servlet.jsp.tagext.BodyTagSupport;
44  
45  /**
46   * Renders a time input field with a label.
47   * <br />
48   * Short syntax of:
49   * <p/>
50   * <pre>
51   * &lt;tc:panel>
52   *   &lt;f:facet name="layout">
53   *     &lt;tc:gridLayout columns="fixed;*"/>
54   *   &lt;/f:facet>
55   *   &lt;tc:label value="#{label}" for="@auto"/>
56   *   &lt;tc:time value="#{value}">
57   *     ...
58   *   &lt;/tc:in>
59   * &lt;/tc:panel>
60   * </pre>
61   */
62  @Tag(name = "time")
63  @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.internal.taglib.TimeTag")
64  public class TimeExtensionTag extends BodyTagSupport
65      implements HasValue, HasValueChangeListener, HasValidator, HasIdBindingAndRendered,
66      HasConverter, IsReadonly, IsDisabled, HasOnchange, IsRequired, HasTip,
67      HasValidatorMessage, HasRequiredMessage, HasConverterMessage,
68      HasLabel, HasLabelWidth, IsFocus, IsInline, HasTabIndex {
69  
70    private String binding;
71    private String converter;
72    private String validator;
73    private String disabled;
74    private String focus;
75    private String label;
76    private String readonly;
77    private String rendered;
78    private String required;
79    private String tip;
80    private String value;
81    private String valueChangeListener;
82    private String inline;
83    private String onchange;
84    private String labelWidth;
85    private String tabIndex;
86    private String validatorMessage;
87    private String converterMessage;
88    private String requiredMessage;
89  
90    private LabelExtensionTag labelTag;
91    private TimeTag timeTag;
92  
93    @Override
94    public int doStartTag() throws JspException {
95  
96      labelTag = new LabelExtensionTag();
97      labelTag.setPageContext(pageContext);
98      if (label != null) {
99        labelTag.setValue(label);
100     }
101     if (tip != null) {
102       labelTag.setTip(tip);
103     }
104     if (rendered != null) {
105       labelTag.setRendered(rendered);
106     }
107     if (labelWidth != null) {
108       labelTag.setColumns(labelWidth + ";*");
109     }
110     labelTag.setParent(getParent());
111     labelTag.doStartTag();
112 
113     timeTag = new TimeTag();
114     timeTag.setPageContext(pageContext);
115     if (value != null) {
116       timeTag.setValue(value);
117     }
118     if (valueChangeListener != null) {
119       timeTag.setValueChangeListener(valueChangeListener);
120     }
121     if (binding != null) {
122       timeTag.setBinding(binding);
123     }
124     /*if (converter != null) {
125       timeTag.setConverter(converter);
126     }*/
127     if (validator != null) {
128       timeTag.setValidator(validator);
129     }
130     if (onchange != null) {
131       timeTag.setOnchange(onchange);
132     }
133     if (disabled != null) {
134       timeTag.setDisabled(disabled);
135     }
136     if (focus != null) {
137       timeTag.setFocus(focus);
138     }
139     if (id != null) {
140       timeTag.setId(id);
141     }
142     if (inline != null) {
143       timeTag.setInline(inline);
144     }
145     if (readonly != null) {
146       timeTag.setReadonly(readonly);
147     }
148     if (required != null) {
149       timeTag.setRequired(required);
150     }
151     if (tabIndex != null) {
152       timeTag.setTabIndex(tabIndex);
153     }
154     if (validatorMessage != null) {
155       timeTag.setValidatorMessage(validatorMessage);
156     }
157     if (converterMessage != null) {
158       timeTag.setConverterMessage(converterMessage);
159     }
160     if (requiredMessage != null) {
161       timeTag.setRequiredMessage(requiredMessage);
162     }
163 
164     timeTag.setParent(labelTag);
165     timeTag.doStartTag();
166 
167     return super.doStartTag();
168   }
169 
170   @Override
171   public int doEndTag() throws JspException {
172     timeTag.doEndTag();
173     labelTag.doEndTag();
174     return super.doEndTag();
175   }
176 
177   @Override
178   public void release() {
179     super.release();
180     binding = null;
181     converter = null;
182     validator = null;
183     disabled = null;
184     labelWidth = null;
185     focus = null;
186     label = null;
187     inline = null;
188     readonly = null;
189     rendered = null;
190     required = null;
191     tip = null;
192     value = null;
193     onchange = null;
194     valueChangeListener = null;
195     tabIndex = null;
196     timeTag = null;
197     labelTag = null;
198     validatorMessage = null;
199     converterMessage = null;
200     requiredMessage = null;
201   }
202 
203   public void setValue(String value) {
204     this.value = value;
205   }
206 
207   public void setValueChangeListener(String valueChangeListener) {
208     this.valueChangeListener = valueChangeListener;
209   }
210 
211   public void setLabel(String label) {
212     this.label = label;
213   }
214 
215   public void setFocus(String focus) {
216     this.focus = focus;
217   }
218 
219   public void setBinding(String binding) {
220     this.binding = binding;
221   }
222 
223   public void setRendered(String rendered) {
224     this.rendered = rendered;
225   }
226 
227   public void setConverter(String converter) {
228     this.converter = converter;
229   }
230 
231   public void setValidator(String validator) {
232     this.validator = validator;
233   }
234 
235   public void setOnchange(String onchange) {
236     this.onchange = onchange;
237   }
238 
239   public void setInline(String inline) {
240     this.inline = inline;
241   }
242 
243   public void setReadonly(String readonly) {
244     this.readonly = readonly;
245   }
246 
247   public void setDisabled(String disabled) {
248     this.disabled = disabled;
249   }
250 
251   public void setRequired(String required) {
252     this.required = required;
253   }
254 
255   public void setTip(String tip) {
256     this.tip = tip;
257   }
258 
259   public void setLabelWidth(String labelWidth) {
260     this.labelWidth = labelWidth;
261   }
262 
263   public void setTabIndex(String tabIndex) {
264     this.tabIndex = tabIndex;
265   }
266 
267   public void setValidatorMessage(String validatorMessage) {
268     this.validatorMessage = validatorMessage;
269   }
270 
271   public void setConverterMessage(String converterMessage) {
272     this.converterMessage = converterMessage;
273   }
274 
275   public void setRequiredMessage(String requiredMessage) {
276     this.requiredMessage = requiredMessage;
277   }
278 }