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.Tag; 021 import org.apache.myfaces.tobago.apt.annotation.ExtensionTag; 022 import org.apache.myfaces.tobago.taglib.component.DateTag; 023 import org.apache.myfaces.tobago.taglib.component.DatePickerTag; 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.HasTip; 029 import org.apache.myfaces.tobago.taglib.decl.HasValidator; 030 import org.apache.myfaces.tobago.taglib.decl.HasValue; 031 import org.apache.myfaces.tobago.taglib.decl.IsDisabled; 032 import org.apache.myfaces.tobago.taglib.decl.IsFocus; 033 import org.apache.myfaces.tobago.taglib.decl.IsInline; 034 import org.apache.myfaces.tobago.taglib.decl.IsReadonly; 035 import org.apache.myfaces.tobago.taglib.decl.IsRequired; 036 import org.apache.myfaces.tobago.taglib.decl.HasOnchange; 037 import org.apache.myfaces.tobago.taglib.decl.HasValueChangeListener; 038 import org.apache.myfaces.tobago.taglib.decl.HasLabelWidth; 039 040 import javax.servlet.jsp.JspException; 041 import javax.servlet.jsp.tagext.BodyTagSupport; 042 043 /* 044 * Created by IntelliJ IDEA. 045 * User: bommel 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 * 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, 071 IsRequired, HasTip, HasLabel, HasLabelWidth, IsFocus, IsInline { 072 073 private String binding; 074 private String converter; 075 private String validator; 076 private String disabled; 077 private String focus; 078 private String label; 079 private String readonly; 080 private String rendered; 081 private String required; 082 private String tip; 083 private String value; 084 private String valueChangeListener; 085 private String inline; 086 private String onchange; 087 private String labelWidth; 088 089 090 private LabelExtensionTag labelTag; 091 private DateTag dateTag; 092 093 @Override 094 public int doStartTag() throws JspException { 095 096 labelTag = new LabelExtensionTag(); 097 labelTag.setPageContext(pageContext); 098 if (label != null) { 099 labelTag.setValue(label); 100 } 101 if (labelWidth != null) { 102 labelTag.setColumns(labelWidth + ";*;fixed"); 103 } else { 104 labelTag.setColumns("fixed;*;fixed"); 105 } 106 if (tip != null) { 107 labelTag.setTip(tip); 108 } 109 if (rendered != null) { 110 labelTag.setRendered(rendered); 111 } 112 labelTag.setParent(getParent()); 113 labelTag.doStartTag(); 114 115 dateTag = new DateTag(); 116 dateTag.setPageContext(pageContext); 117 if (value != null) { 118 dateTag.setValue(value); 119 } 120 if (valueChangeListener != null) { 121 dateTag.setValueChangeListener(valueChangeListener); 122 } 123 if (binding != null) { 124 dateTag.setBinding(binding); 125 } 126 if (converter != null) { 127 dateTag.setConverter(converter); 128 } 129 if (validator != null) { 130 dateTag.setValidator(validator); 131 } 132 if (disabled != null) { 133 dateTag.setDisabled(disabled); 134 } 135 if (onchange != null) { 136 dateTag.setOnchange(onchange); 137 } 138 if (focus != null) { 139 dateTag.setFocus(focus); 140 } 141 if (id != null) { 142 dateTag.setId(id); 143 } 144 if (inline != null) { 145 dateTag.setInline(inline); 146 } 147 if (readonly != null) { 148 dateTag.setReadonly(readonly); 149 } 150 if (required != null) { 151 dateTag.setRequired(required); 152 } 153 dateTag.setParent(labelTag); 154 dateTag.doStartTag(); 155 156 return super.doStartTag(); 157 } 158 159 @Override 160 public int doEndTag() throws JspException { 161 dateTag.doEndTag(); 162 FormTag formTag = new FormTag(); 163 formTag.setPageContext(pageContext); 164 formTag.setParent(labelTag); 165 formTag.doStartTag(); 166 167 DatePickerTag datePicker = new DatePickerTag(); 168 datePicker.setPageContext(pageContext); 169 datePicker.setFor("@auto"); 170 datePicker.setParent(formTag); 171 datePicker.doStartTag(); 172 datePicker.doEndTag(); 173 formTag.doEndTag(); 174 175 labelTag.doEndTag(); 176 return super.doEndTag(); 177 } 178 179 @Override 180 public void release() { 181 super.release(); 182 binding = null; 183 converter = null; 184 validator = null; 185 disabled = null; 186 labelWidth = null; 187 focus = null; 188 label = null; 189 inline = null; 190 readonly = null; 191 rendered = null; 192 required = null; 193 tip = null; 194 value = null; 195 valueChangeListener = null; 196 onchange = null; 197 labelTag = null; 198 dateTag = null; 199 } 200 201 public void setValue(String value) { 202 this.value = value; 203 } 204 205 public void setValueChangeListener(String valueChangeListener) { 206 this.valueChangeListener = valueChangeListener; 207 } 208 209 public void setLabel(String label) { 210 this.label = label; 211 } 212 213 public void setOnchange(String onchange) { 214 this.onchange = onchange; 215 } 216 217 public void setFocus(String focus) { 218 this.focus = focus; 219 } 220 221 public void setBinding(String binding) { 222 this.binding = binding; 223 } 224 225 public void setRendered(String rendered) { 226 this.rendered = rendered; 227 } 228 229 public void setConverter(String converter) { 230 this.converter = converter; 231 } 232 233 public void setValidator(String validator) { 234 this.validator = validator; 235 } 236 public void setInline(String inline) { 237 this.inline = inline; 238 } 239 240 public void setReadonly(String readonly) { 241 this.readonly = readonly; 242 } 243 244 public void setDisabled(String disabled) { 245 this.disabled = disabled; 246 } 247 248 public void setRequired(String required) { 249 this.required = required; 250 } 251 252 public void setTip(String tip) { 253 this.tip = tip; 254 } 255 256 public void setLabelWidth(String labelWidth) { 257 this.labelWidth = labelWidth; 258 } 259 }