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