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 * <tc:panel>
056 * <f:facet name="layout">
057 * <tc:gridLayout columns="fixed;*"/>
058 * </f:facet>
059 * <tc:label value="#{label}" for="@auto"/>
060 * <tc:date value="#{value}">
061 * ...
062 * </tc:in>
063 * </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 if (markup != null) {
116 labelTag.setMarkup(markup);
117 }
118 labelTag.setParent(getParent());
119 labelTag.doStartTag();
120
121 dateTag = new DateTag();
122 dateTag.setPageContext(pageContext);
123 if (value != null) {
124 dateTag.setValue(value);
125 }
126 if (valueChangeListener != null) {
127 dateTag.setValueChangeListener(valueChangeListener);
128 }
129 if (binding != null) {
130 dateTag.setBinding(binding);
131 }
132 if (converter != null) {
133 dateTag.setConverter(converter);
134 }
135 if (validator != null) {
136 dateTag.setValidator(validator);
137 }
138 if (disabled != null) {
139 dateTag.setDisabled(disabled);
140 }
141 if (onchange != null) {
142 dateTag.setOnchange(onchange);
143 }
144 if (focus != null) {
145 dateTag.setFocus(focus);
146 }
147 if (id != null) {
148 dateTag.setId(id);
149 }
150 if (inline != null) {
151 dateTag.setInline(inline);
152 }
153 if (readonly != null) {
154 dateTag.setReadonly(readonly);
155 }
156 if (required != null) {
157 dateTag.setRequired(required);
158 }
159 if (markup != null) {
160 dateTag.setMarkup(markup);
161 }
162 if (tabIndex != null) {
163 dateTag.setTabIndex(tabIndex);
164 }
165 dateTag.setParent(labelTag);
166 dateTag.doStartTag();
167
168 return super.doStartTag();
169 }
170
171 @Override
172 public int doEndTag() throws JspException {
173 dateTag.doEndTag();
174 FormTag formTag = new FormTag();
175 formTag.setPageContext(pageContext);
176 formTag.setParent(labelTag);
177 formTag.doStartTag();
178
179 DatePickerTag datePicker = new DatePickerTag();
180 datePicker.setPageContext(pageContext);
181 datePicker.setFor("@auto");
182 if (tabIndex != null) {
183 datePicker.setTabIndex(tabIndex);
184 }
185 datePicker.setParent(formTag);
186 datePicker.doStartTag();
187 datePicker.doEndTag();
188 formTag.doEndTag();
189
190 labelTag.doEndTag();
191 return super.doEndTag();
192 }
193
194 @Override
195 public void release() {
196 super.release();
197 binding = null;
198 converter = null;
199 validator = null;
200 disabled = null;
201 labelWidth = null;
202 focus = null;
203 label = null;
204 inline = null;
205 readonly = null;
206 rendered = null;
207 required = null;
208 tip = null;
209 value = null;
210 valueChangeListener = null;
211 onchange = null;
212 markup = null;
213 tabIndex = null;
214 labelTag = null;
215 dateTag = null;
216 }
217
218 public void setValue(String value) {
219 this.value = value;
220 }
221
222 public void setValueChangeListener(String valueChangeListener) {
223 this.valueChangeListener = valueChangeListener;
224 }
225
226 public void setLabel(String label) {
227 this.label = label;
228 }
229
230 public void setOnchange(String onchange) {
231 this.onchange = onchange;
232 }
233
234 public void setFocus(String focus) {
235 this.focus = focus;
236 }
237
238 public void setBinding(String binding) {
239 this.binding = binding;
240 }
241
242 public void setRendered(String rendered) {
243 this.rendered = rendered;
244 }
245
246 public void setConverter(String converter) {
247 this.converter = converter;
248 }
249
250 public void setValidator(String validator) {
251 this.validator = validator;
252 }
253
254 public void setInline(String inline) {
255 this.inline = inline;
256 }
257
258 public void setReadonly(String readonly) {
259 this.readonly = readonly;
260 }
261
262 public void setDisabled(String disabled) {
263 this.disabled = disabled;
264 }
265
266 public void setRequired(String required) {
267 this.required = required;
268 }
269
270 public void setTip(String tip) {
271 this.tip = tip;
272 }
273
274 public void setLabelWidth(String labelWidth) {
275 this.labelWidth = labelWidth;
276 }
277
278 public void setMarkup(String markup) {
279 this.markup = markup;
280 }
281
282 public void setTabIndex(String tabIndex) {
283 this.tabIndex = tabIndex;
284 }
285 }