001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *   http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    
020    package org.apache.myfaces.tobago.taglib.extension;
021    
022    import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
023    import org.apache.myfaces.tobago.apt.annotation.Tag;
024    import org.apache.myfaces.tobago.taglib.component.DatePickerTag;
025    import org.apache.myfaces.tobago.taglib.component.DateTag;
026    import org.apache.myfaces.tobago.taglib.component.FormTag;
027    import org.apache.myfaces.tobago.taglib.decl.HasConverter;
028    import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered;
029    import org.apache.myfaces.tobago.taglib.decl.HasLabel;
030    import org.apache.myfaces.tobago.taglib.decl.HasLabelWidth;
031    import org.apache.myfaces.tobago.taglib.decl.HasMarkup;
032    import org.apache.myfaces.tobago.taglib.decl.HasOnchange;
033    import org.apache.myfaces.tobago.taglib.decl.HasTabIndex;
034    import org.apache.myfaces.tobago.taglib.decl.HasTip;
035    import org.apache.myfaces.tobago.taglib.decl.HasValidator;
036    import org.apache.myfaces.tobago.taglib.decl.HasValue;
037    import org.apache.myfaces.tobago.taglib.decl.HasValueChangeListener;
038    import org.apache.myfaces.tobago.taglib.decl.IsDisabled;
039    import org.apache.myfaces.tobago.taglib.decl.IsFocus;
040    import org.apache.myfaces.tobago.taglib.decl.IsInline;
041    import org.apache.myfaces.tobago.taglib.decl.IsReadonly;
042    import org.apache.myfaces.tobago.taglib.decl.IsRequired;
043    
044    import javax.servlet.jsp.JspException;
045    import javax.servlet.jsp.tagext.BodyTagSupport;
046    
047    /*
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     * <p/>
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        if (markup != null) {
118          labelTag.setMarkup(markup);
119        }
120        labelTag.setParent(getParent());
121        labelTag.doStartTag();
122    
123        dateTag = new DateTag();
124        dateTag.setPageContext(pageContext);
125        if (value != null) {
126          dateTag.setValue(value);
127        }
128        if (valueChangeListener != null) {
129          dateTag.setValueChangeListener(valueChangeListener);
130        }
131        if (binding != null) {
132          dateTag.setBinding(binding);
133        }
134        if (converter != null) {
135          dateTag.setConverter(converter);
136        }
137        if (validator != null) {
138          dateTag.setValidator(validator);
139        }
140        if (disabled != null) {
141          dateTag.setDisabled(disabled);
142        }
143        if (onchange != null) {
144          dateTag.setOnchange(onchange);
145        }
146        if (focus != null) {
147          dateTag.setFocus(focus);
148        }
149        if (id != null) {
150          dateTag.setId(id);
151        }
152        if (inline != null) {
153          dateTag.setInline(inline);
154        }
155        if (readonly != null) {
156          dateTag.setReadonly(readonly);
157        }
158        if (required != null) {
159          dateTag.setRequired(required);
160        }
161        if (markup != null) {
162          dateTag.setMarkup(markup);
163        }
164        if (tabIndex != null) {
165          dateTag.setTabIndex(tabIndex);
166        }
167        dateTag.setParent(labelTag);
168        dateTag.doStartTag();
169    
170        return super.doStartTag();
171      }
172    
173      @Override
174      public int doEndTag() throws JspException {
175        dateTag.doEndTag();
176        FormTag formTag = new FormTag();
177        formTag.setPageContext(pageContext);
178        formTag.setParent(labelTag);
179        formTag.doStartTag();
180    
181        DatePickerTag datePicker = new DatePickerTag();
182        datePicker.setPageContext(pageContext);
183        datePicker.setFor("@auto");
184        if (tabIndex != null) {
185          datePicker.setTabIndex(tabIndex);
186        }
187        datePicker.setParent(formTag);
188        datePicker.doStartTag();
189        datePicker.doEndTag();
190        formTag.doEndTag();
191    
192        labelTag.doEndTag();
193        return super.doEndTag();
194      }
195    
196      @Override
197      public void release() {
198        super.release();
199        binding = null;
200        converter = null;
201        validator = null;
202        disabled = null;
203        labelWidth = null;
204        focus = null;
205        label = null;
206        inline = null;
207        readonly = null;
208        rendered = null;
209        required = null;
210        tip = null;
211        value = null;
212        valueChangeListener = null;
213        onchange = null;
214        markup = null;
215        tabIndex = null;
216        labelTag = null;
217        dateTag = null;
218      }
219    
220      public void setValue(String value) {
221        this.value = value;
222      }
223    
224      public void setValueChangeListener(String valueChangeListener) {
225        this.valueChangeListener = valueChangeListener;
226      }
227    
228      public void setLabel(String label) {
229        this.label = label;
230      }
231    
232      public void setOnchange(String onchange) {
233        this.onchange = onchange;
234      }
235    
236      public void setFocus(String focus) {
237        this.focus = focus;
238      }
239    
240      public void setBinding(String binding) {
241        this.binding = binding;
242      }
243    
244      public void setRendered(String rendered) {
245        this.rendered = rendered;
246      }
247    
248      public void setConverter(String converter) {
249        this.converter = converter;
250      }
251    
252      public void setValidator(String validator) {
253        this.validator = validator;
254      }
255    
256      public void setInline(String inline) {
257        this.inline = inline;
258      }
259    
260      public void setReadonly(String readonly) {
261        this.readonly = readonly;
262      }
263    
264      public void setDisabled(String disabled) {
265        this.disabled = disabled;
266      }
267    
268      public void setRequired(String required) {
269        this.required = required;
270      }
271    
272      public void setTip(String tip) {
273        this.tip = tip;
274      }
275    
276      public void setLabelWidth(String labelWidth) {
277        this.labelWidth = labelWidth;
278      }
279    
280      public void setMarkup(String markup) {
281        this.markup = markup;
282      }
283    
284      public void setTabIndex(String tabIndex) {
285        this.tabIndex = tabIndex;
286      }
287    }