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