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     * Created by IntelliJ IDEA.
047     * User: bommel
048     * Date: 19.12.2005
049     * Time: 20:13:26
050     */
051    /**
052     * Renders a date input field with a date picker and a label.
053     * <br />
054     * Short syntax of:
055     *
056     * <pre>
057     * &lt;tc:panel>
058     *   &lt;f:facet name="layout">
059     *     &lt;tc:gridLayout columns="fixed;*"/>
060     *   &lt;/f:facet>
061     *   &lt;tc:label value="#{label}" for="@auto"/>
062     *   &lt;tc:date value="#{value}">
063     *     ...
064     *   &lt;/tc:in>
065     * &lt;/tc:panel>
066     * </pre>
067     */
068    @Tag(name = "date")
069    @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.DateTag")
070    public class DateExtensionTag extends BodyTagSupport
071        implements HasValue, HasValueChangeListener, HasValidator, HasIdBindingAndRendered,
072        HasConverter, IsReadonly, IsDisabled, HasOnchange, IsRequired, HasTip, 
073        HasLabel, HasMarkup, HasLabelWidth, IsFocus, IsInline, HasTabIndex {
074    
075      private static final long serialVersionUID = 2044784791513107420L;
076    
077      private String binding;
078      private String converter;
079      private String validator;
080      private String disabled;
081      private String focus;
082      private String label;
083      private String readonly;
084      private String rendered;
085      private String required;
086      private String tip;
087      private String value;
088      private String valueChangeListener;
089      private String inline;
090      private String onchange;
091      private String tabIndex;
092      private String markup;
093    
094      private String labelWidth;
095      private LabelExtensionTag labelTag;
096      private DateTag dateTag;
097    
098      @Override
099      public int doStartTag() throws JspException {
100    
101        labelTag = new LabelExtensionTag();
102        labelTag.setPageContext(pageContext);
103        if (label != null) {
104          labelTag.setValue(label);
105        }
106        if (labelWidth != null) {
107          labelTag.setColumns(labelWidth + ";*;fixed");
108        } else {
109          labelTag.setColumns("fixed;*;fixed");
110        }
111        if (tip != null) {
112          labelTag.setTip(tip);
113        }
114        if (rendered != null) {
115          labelTag.setRendered(rendered);
116        }
117        labelTag.setParent(getParent());
118        labelTag.doStartTag();
119    
120        dateTag = new DateTag();
121        dateTag.setPageContext(pageContext);
122        if (value != null) {
123          dateTag.setValue(value);
124        }
125        if (valueChangeListener != null) {
126          dateTag.setValueChangeListener(valueChangeListener);
127        }
128        if (binding != null) {
129          dateTag.setBinding(binding);
130        }
131        if (converter != null) {
132          dateTag.setConverter(converter);
133        }
134        if (validator != null) {
135          dateTag.setValidator(validator);
136        }
137        if (disabled != null) {
138          dateTag.setDisabled(disabled);
139        }
140        if (onchange != null) {
141          dateTag.setOnchange(onchange);
142        }
143        if (focus != null) {
144          dateTag.setFocus(focus);
145        }
146        if (id != null) {
147          dateTag.setId(id);
148        }
149        if (inline != null) {
150          dateTag.setInline(inline);
151        }
152        if (readonly != null) {
153          dateTag.setReadonly(readonly);
154        }
155        if (required != null) {
156          dateTag.setRequired(required);
157        }
158        if (markup != null) {
159          dateTag.setMarkup(markup);
160        }
161        if (tabIndex != null) {
162          dateTag.setTabIndex(tabIndex);
163        }
164        dateTag.setParent(labelTag);
165        dateTag.doStartTag();
166    
167        return super.doStartTag();
168      }
169    
170      @Override
171      public int doEndTag() throws JspException {
172        dateTag.doEndTag();
173        FormTag formTag = new FormTag();
174        formTag.setPageContext(pageContext);
175        formTag.setParent(labelTag);
176        formTag.doStartTag();
177    
178        DatePickerTag datePicker = new DatePickerTag();
179        datePicker.setPageContext(pageContext);
180        datePicker.setFor("@auto");
181        if (tabIndex != null) {
182          datePicker.setTabIndex(tabIndex);
183        }    
184        datePicker.setParent(formTag);
185        datePicker.doStartTag();
186        datePicker.doEndTag();
187        formTag.doEndTag();
188    
189        labelTag.doEndTag();
190        return super.doEndTag();
191      }
192    
193      @Override
194      public void release() {
195        super.release();
196        binding = null;
197        converter = null;
198        validator = null;
199        disabled = null;
200        labelWidth = null;
201        focus = null;
202        label = null;
203        inline = null;
204        readonly = null;
205        rendered = null;
206        required = null;
207        tip = null;
208        value = null;
209        valueChangeListener = null;
210        onchange = null;
211        markup = null;
212        tabIndex = null;
213        labelTag = null;
214        dateTag = null;
215      }
216    
217      public void setValue(String value) {
218        this.value = value;
219      }
220    
221      public void setValueChangeListener(String valueChangeListener) {
222        this.valueChangeListener = valueChangeListener;
223      }
224    
225      public void setLabel(String label) {
226        this.label = label;
227      }
228    
229      public void setOnchange(String onchange) {
230        this.onchange = onchange;
231      }
232    
233      public void setFocus(String focus) {
234        this.focus = focus;
235      }
236    
237      public void setBinding(String binding) {
238        this.binding = binding;
239      }
240    
241      public void setRendered(String rendered) {
242        this.rendered = rendered;
243      }
244    
245      public void setConverter(String converter) {
246        this.converter = converter;
247      }
248    
249      public void setValidator(String validator) {
250        this.validator = validator;
251      }
252      public void setInline(String inline) {
253        this.inline = inline;
254      }
255    
256      public void setReadonly(String readonly) {
257        this.readonly = readonly;
258      }
259    
260      public void setDisabled(String disabled) {
261        this.disabled = disabled;
262      }
263    
264      public void setRequired(String required) {
265        this.required = required;
266      }
267    
268      public void setTip(String tip) {
269        this.tip = tip;
270      }
271    
272      public void setLabelWidth(String labelWidth) {
273        this.labelWidth = labelWidth;
274      }
275    
276      public void setMarkup(String markup) {
277        this.markup = markup;
278      }
279    
280      public void setTabIndex(String tabIndex) {
281        this.tabIndex = tabIndex;
282      }
283    }