001    package org.apache.myfaces.tobago.taglib.extension;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
021    import org.apache.myfaces.tobago.apt.annotation.Tag;
022    import org.apache.myfaces.tobago.taglib.component.DatePickerTag;
023    import org.apache.myfaces.tobago.taglib.component.DateTag;
024    import org.apache.myfaces.tobago.taglib.component.FormTag;
025    import org.apache.myfaces.tobago.taglib.decl.HasConverter;
026    import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered;
027    import org.apache.myfaces.tobago.taglib.decl.HasLabel;
028    import org.apache.myfaces.tobago.taglib.decl.HasLabelWidth;
029    import org.apache.myfaces.tobago.taglib.decl.HasMarkup;
030    import org.apache.myfaces.tobago.taglib.decl.HasOnchange;
031    import org.apache.myfaces.tobago.taglib.decl.HasTabIndex;
032    import org.apache.myfaces.tobago.taglib.decl.HasTip;
033    import org.apache.myfaces.tobago.taglib.decl.HasValidator;
034    import org.apache.myfaces.tobago.taglib.decl.HasValue;
035    import org.apache.myfaces.tobago.taglib.decl.HasValueChangeListener;
036    import org.apache.myfaces.tobago.taglib.decl.IsDisabled;
037    import org.apache.myfaces.tobago.taglib.decl.IsFocus;
038    import org.apache.myfaces.tobago.taglib.decl.IsInline;
039    import org.apache.myfaces.tobago.taglib.decl.IsReadonly;
040    import org.apache.myfaces.tobago.taglib.decl.IsRequired;
041    
042    import javax.servlet.jsp.JspException;
043    import javax.servlet.jsp.tagext.BodyTagSupport;
044    
045    /*
046     * Date: 19.12.2005
047     * Time: 20:13:26
048     */
049    /**
050     * Renders a date input field with a date picker and a label.
051     * <br />
052     * Short syntax of:
053     * <p/>
054     * <pre>
055     * &lt;tc:panel>
056     *   &lt;f:facet name="layout">
057     *     &lt;tc:gridLayout columns="fixed;*"/>
058     *   &lt;/f:facet>
059     *   &lt;tc:label value="#{label}" for="@auto"/>
060     *   &lt;tc:date value="#{value}">
061     *     ...
062     *   &lt;/tc:in>
063     * &lt;/tc:panel>
064     * </pre>
065     */
066    @Tag(name = "date")
067    @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.DateTag")
068    public class DateExtensionTag extends BodyTagSupport
069        implements HasValue, HasValueChangeListener, HasValidator, HasIdBindingAndRendered,
070        HasConverter, IsReadonly, IsDisabled, HasOnchange, IsRequired, HasTip,
071        HasLabel, HasMarkup, HasLabelWidth, IsFocus, IsInline, HasTabIndex {
072    
073      private static final long serialVersionUID = 2044784791513107420L;
074    
075      private String binding;
076      private String converter;
077      private String validator;
078      private String disabled;
079      private String focus;
080      private String label;
081      private String readonly;
082      private String rendered;
083      private String required;
084      private String tip;
085      private String value;
086      private String valueChangeListener;
087      private String inline;
088      private String onchange;
089      private String tabIndex;
090      private String markup;
091    
092      private String labelWidth;
093      private LabelExtensionTag labelTag;
094      private DateTag dateTag;
095    
096      @Override
097      public int doStartTag() throws JspException {
098    
099        labelTag = new LabelExtensionTag();
100        labelTag.setPageContext(pageContext);
101        if (label != null) {
102          labelTag.setValue(label);
103        }
104        if (labelWidth != null) {
105          labelTag.setColumns(labelWidth + ";*;fixed");
106        } else {
107          labelTag.setColumns("fixed;*;fixed");
108        }
109        if (tip != null) {
110          labelTag.setTip(tip);
111        }
112        if (rendered != null) {
113          labelTag.setRendered(rendered);
114        }
115        labelTag.setParent(getParent());
116        labelTag.doStartTag();
117    
118        dateTag = new DateTag();
119        dateTag.setPageContext(pageContext);
120        if (value != null) {
121          dateTag.setValue(value);
122        }
123        if (valueChangeListener != null) {
124          dateTag.setValueChangeListener(valueChangeListener);
125        }
126        if (binding != null) {
127          dateTag.setBinding(binding);
128        }
129        if (converter != null) {
130          dateTag.setConverter(converter);
131        }
132        if (validator != null) {
133          dateTag.setValidator(validator);
134        }
135        if (disabled != null) {
136          dateTag.setDisabled(disabled);
137        }
138        if (onchange != null) {
139          dateTag.setOnchange(onchange);
140        }
141        if (focus != null) {
142          dateTag.setFocus(focus);
143        }
144        if (id != null) {
145          dateTag.setId(id);
146        }
147        if (inline != null) {
148          dateTag.setInline(inline);
149        }
150        if (readonly != null) {
151          dateTag.setReadonly(readonly);
152        }
153        if (required != null) {
154          dateTag.setRequired(required);
155        }
156        if (markup != null) {
157          dateTag.setMarkup(markup);
158        }
159        if (tabIndex != null) {
160          dateTag.setTabIndex(tabIndex);
161        }
162        dateTag.setParent(labelTag);
163        dateTag.doStartTag();
164    
165        return super.doStartTag();
166      }
167    
168      @Override
169      public int doEndTag() throws JspException {
170        dateTag.doEndTag();
171        FormTag formTag = new FormTag();
172        formTag.setPageContext(pageContext);
173        formTag.setParent(labelTag);
174        formTag.doStartTag();
175    
176        DatePickerTag datePicker = new DatePickerTag();
177        datePicker.setPageContext(pageContext);
178        datePicker.setFor("@auto");
179        if (tabIndex != null) {
180          datePicker.setTabIndex(tabIndex);
181        }
182        datePicker.setParent(formTag);
183        datePicker.doStartTag();
184        datePicker.doEndTag();
185        formTag.doEndTag();
186    
187        labelTag.doEndTag();
188        return super.doEndTag();
189      }
190    
191      @Override
192      public void release() {
193        super.release();
194        binding = null;
195        converter = null;
196        validator = null;
197        disabled = null;
198        labelWidth = null;
199        focus = null;
200        label = null;
201        inline = null;
202        readonly = null;
203        rendered = null;
204        required = null;
205        tip = null;
206        value = null;
207        valueChangeListener = null;
208        onchange = null;
209        markup = null;
210        tabIndex = null;
211        labelTag = null;
212        dateTag = null;
213      }
214    
215      public void setValue(String value) {
216        this.value = value;
217      }
218    
219      public void setValueChangeListener(String valueChangeListener) {
220        this.valueChangeListener = valueChangeListener;
221      }
222    
223      public void setLabel(String label) {
224        this.label = label;
225      }
226    
227      public void setOnchange(String onchange) {
228        this.onchange = onchange;
229      }
230    
231      public void setFocus(String focus) {
232        this.focus = focus;
233      }
234    
235      public void setBinding(String binding) {
236        this.binding = binding;
237      }
238    
239      public void setRendered(String rendered) {
240        this.rendered = rendered;
241      }
242    
243      public void setConverter(String converter) {
244        this.converter = converter;
245      }
246    
247      public void setValidator(String validator) {
248        this.validator = validator;
249      }
250    
251      public void setInline(String inline) {
252        this.inline = inline;
253      }
254    
255      public void setReadonly(String readonly) {
256        this.readonly = readonly;
257      }
258    
259      public void setDisabled(String disabled) {
260        this.disabled = disabled;
261      }
262    
263      public void setRequired(String required) {
264        this.required = required;
265      }
266    
267      public void setTip(String tip) {
268        this.tip = tip;
269      }
270    
271      public void setLabelWidth(String labelWidth) {
272        this.labelWidth = labelWidth;
273      }
274    
275      public void setMarkup(String markup) {
276        this.markup = markup;
277      }
278    
279      public void setTabIndex(String tabIndex) {
280        this.tabIndex = tabIndex;
281      }
282    }