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.TimeTag;
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.HasOnchange;
030    import org.apache.myfaces.tobago.taglib.decl.HasTabIndex;
031    import org.apache.myfaces.tobago.taglib.decl.HasTip;
032    import org.apache.myfaces.tobago.taglib.decl.HasValidator;
033    import org.apache.myfaces.tobago.taglib.decl.HasValue;
034    import org.apache.myfaces.tobago.taglib.decl.HasValueChangeListener;
035    import org.apache.myfaces.tobago.taglib.decl.IsDisabled;
036    import org.apache.myfaces.tobago.taglib.decl.IsFocus;
037    import org.apache.myfaces.tobago.taglib.decl.IsInline;
038    import org.apache.myfaces.tobago.taglib.decl.IsReadonly;
039    import org.apache.myfaces.tobago.taglib.decl.IsRequired;
040    
041    import javax.servlet.jsp.JspException;
042    import javax.servlet.jsp.tagext.BodyTagSupport;
043    
044    /**
045     * Renders a time input field with a label.
046     * <br />
047     * Short syntax of:
048     * <p/>
049     * <pre>
050     * &lt;tc:panel>
051     *   &lt;f:facet name="layout">
052     *     &lt;tc:gridLayout columns="fixed;*"/>
053     *   &lt;/f:facet>
054     *   &lt;tc:label value="#{label}" for="@auto"/>
055     *   &lt;tc:time value="#{value}">
056     *     ...
057     *   &lt;/tc:in>
058     * &lt;/tc:panel>
059     * </pre>
060     */
061    @Tag(name = "time")
062    @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.TimeTag")
063    public class TimeExtensionTag extends BodyTagSupport
064        implements HasValue, HasValueChangeListener, HasValidator, HasIdBindingAndRendered,
065        HasConverter, IsReadonly, IsDisabled, HasOnchange, IsRequired, HasTip,
066        HasLabel, HasLabelWidth, IsFocus, IsInline, HasTabIndex {
067    
068      private String binding;
069      private String converter;
070      private String validator;
071      private String disabled;
072      private String focus;
073      private String label;
074      private String readonly;
075      private String rendered;
076      private String required;
077      private String tip;
078      private String value;
079      private String valueChangeListener;
080      private String inline;
081      private String onchange;
082      private String labelWidth;
083      private String tabIndex;
084    
085      private LabelExtensionTag labelTag;
086      private TimeTag timeTag;
087    
088      @Override
089      public int doStartTag() throws JspException {
090    
091        labelTag = new LabelExtensionTag();
092        labelTag.setPageContext(pageContext);
093        if (label != null) {
094          labelTag.setValue(label);
095        }
096        if (tip != null) {
097          labelTag.setTip(tip);
098        }
099        if (rendered != null) {
100          labelTag.setRendered(rendered);
101        }
102        if (labelWidth != null) {
103          labelTag.setColumns(labelWidth + ";*");
104        }
105        labelTag.setParent(getParent());
106        labelTag.doStartTag();
107    
108        timeTag = new TimeTag();
109        timeTag.setPageContext(pageContext);
110        if (value != null) {
111          timeTag.setValue(value);
112        }
113        if (valueChangeListener != null) {
114          timeTag.setValueChangeListener(valueChangeListener);
115        }
116        if (binding != null) {
117          timeTag.setBinding(binding);
118        }
119        if (converter != null) {
120          timeTag.setConverter(converter);
121        }
122        if (validator != null) {
123          timeTag.setValidator(validator);
124        }
125        if (onchange != null) {
126          timeTag.setOnchange(onchange);
127        }
128        if (disabled != null) {
129          timeTag.setDisabled(disabled);
130        }
131        if (focus != null) {
132          timeTag.setFocus(focus);
133        }
134        if (id != null) {
135          timeTag.setId(id);
136        }
137        if (inline != null) {
138          timeTag.setInline(inline);
139        }
140        if (readonly != null) {
141          timeTag.setReadonly(readonly);
142        }
143        if (required != null) {
144          timeTag.setRequired(required);
145        }
146        if (tabIndex != null) {
147          timeTag.setTabIndex(tabIndex);
148        }
149        timeTag.setParent(labelTag);
150        timeTag.doStartTag();
151    
152        return super.doStartTag();
153      }
154    
155      @Override
156      public int doEndTag() throws JspException {
157        timeTag.doEndTag();
158        labelTag.doEndTag();
159        return super.doEndTag();
160      }
161    
162      @Override
163      public void release() {
164        super.release();
165        binding = null;
166        converter = null;
167        validator = null;
168        disabled = null;
169        labelWidth = null;
170        focus = null;
171        label = null;
172        inline = null;
173        readonly = null;
174        rendered = null;
175        required = null;
176        tip = null;
177        value = null;
178        onchange = null;
179        valueChangeListener = null;
180        tabIndex = null;
181        timeTag = null;
182        labelTag = null;
183      }
184    
185      public void setValue(String value) {
186        this.value = value;
187      }
188    
189      public void setValueChangeListener(String valueChangeListener) {
190        this.valueChangeListener = valueChangeListener;
191      }
192    
193      public void setLabel(String label) {
194        this.label = label;
195      }
196    
197      public void setFocus(String focus) {
198        this.focus = focus;
199      }
200    
201      public void setBinding(String binding) {
202        this.binding = binding;
203      }
204    
205      public void setRendered(String rendered) {
206        this.rendered = rendered;
207      }
208    
209      public void setConverter(String converter) {
210        this.converter = converter;
211      }
212    
213      public void setValidator(String validator) {
214        this.validator = validator;
215      }
216    
217      public void setOnchange(String onchange) {
218        this.onchange = onchange;
219      }
220    
221      public void setInline(String inline) {
222        this.inline = inline;
223      }
224    
225      public void setReadonly(String readonly) {
226        this.readonly = readonly;
227      }
228    
229      public void setDisabled(String disabled) {
230        this.disabled = disabled;
231      }
232    
233      public void setRequired(String required) {
234        this.required = required;
235      }
236    
237      public void setTip(String tip) {
238        this.tip = tip;
239      }
240    
241      public void setLabelWidth(String labelWidth) {
242        this.labelWidth = labelWidth;
243      }
244    
245      public void setTabIndex(String tabIndex) {
246        this.tabIndex = tabIndex;
247      }
248    }