View Javadoc

1   package org.apache.myfaces.tobago.taglib.extension;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
21  import org.apache.myfaces.tobago.apt.annotation.Tag;
22  import org.apache.myfaces.tobago.internal.taglib.InTag;
23  import org.apache.myfaces.tobago.taglib.decl.HasConverter;
24  import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered;
25  import org.apache.myfaces.tobago.taglib.decl.HasLabel;
26  import org.apache.myfaces.tobago.taglib.decl.HasLabelWidth;
27  import org.apache.myfaces.tobago.taglib.decl.HasMarkup;
28  import org.apache.myfaces.tobago.taglib.decl.HasOnchange;
29  import org.apache.myfaces.tobago.taglib.decl.HasSuggestMethod;
30  import org.apache.myfaces.tobago.taglib.decl.HasTabIndex;
31  import org.apache.myfaces.tobago.taglib.decl.HasTip;
32  import org.apache.myfaces.tobago.taglib.decl.HasValidator;
33  import org.apache.myfaces.tobago.taglib.decl.HasValue;
34  import org.apache.myfaces.tobago.taglib.decl.HasValueChangeListener;
35  import org.apache.myfaces.tobago.taglib.decl.IsDisabled;
36  import org.apache.myfaces.tobago.taglib.decl.IsFocus;
37  import org.apache.myfaces.tobago.taglib.decl.IsPassword;
38  import org.apache.myfaces.tobago.taglib.decl.IsReadonly;
39  import org.apache.myfaces.tobago.taglib.decl.IsRequired;
40  import org.apache.myfaces.tobago.taglib.decl.HasValidatorMessage;
41  import org.apache.myfaces.tobago.taglib.decl.HasRequiredMessage;
42  import org.apache.myfaces.tobago.taglib.decl.HasConverterMessage;
43  
44  import javax.servlet.jsp.JspException;
45  import javax.servlet.jsp.tagext.BodyTagSupport;
46  
47  /**
48   * Renders a text input field with a label.
49   * <br />
50   * Short syntax of:
51   * <p/>
52   * <pre>
53   * &lt;tc:panel>
54   *   &lt;f:facet name="layout">
55   *     &lt;tc:gridLayout columns="fixed;*"/>
56   *   &lt;/f:facet>
57   *   &lt;tc:label value="#{label}" for="@auto"/>
58   *   &lt;tc:in value="#{value}">
59   *     ...
60   *   &lt;/tc:in>
61   * &lt;/tc:panel>
62   * </pre>
63   */
64  
65  @Tag(name = "in")
66  @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.internal.taglib.InTag")
67  public class InExtensionTag extends BodyTagSupport
68      implements HasValue, HasValueChangeListener, HasValidator, HasIdBindingAndRendered,
69      HasConverter, IsReadonly, IsDisabled, HasOnchange, HasMarkup, IsRequired,
70      HasValidatorMessage, HasRequiredMessage, HasConverterMessage,
71      HasTip, HasLabel, HasLabelWidth, IsPassword, IsFocus, HasSuggestMethod, HasTabIndex {
72  
73    private String binding;
74    private String converter;
75    private String validator;
76    private String disabled;
77    private String focus;
78    private String label;
79    private String password;
80    private String readonly;
81    private String rendered;
82    private String required;
83    private String tip;
84    private String value;
85    private String valueChangeListener;
86    private String onchange;
87    private String suggestMethod;
88    private String markup;
89    private String labelWidth;
90    private String tabIndex;
91    private String validatorMessage;
92    private String converterMessage;
93    private String requiredMessage;
94  
95    private LabelExtensionTag labelTag;
96    private InTag inTag;
97  
98    @Override
99    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 (tip != null) {
107       labelTag.setTip(tip);
108     }
109     if (rendered != null) {
110       labelTag.setRendered(rendered);
111     }
112     if (labelWidth != null) {
113       labelTag.setColumns(labelWidth + ";*");
114     }
115     if (markup != null) {
116       labelTag.setMarkup(markup);
117     }
118     labelTag.setParent(getParent());
119     labelTag.doStartTag();
120 
121     inTag = new InTag();
122     inTag.setPageContext(pageContext);
123     if (value != null) {
124       inTag.setValue(value);
125     }
126     if (valueChangeListener != null) {
127       inTag.setValueChangeListener(valueChangeListener);
128     }
129     if (binding != null) {
130       inTag.setBinding(binding);
131     }
132     if (converter != null) {
133       inTag.setConverter(converter);
134     }
135     if (validator != null) {
136       inTag.setValidator(validator);
137     }
138     if (onchange != null) {
139       inTag.setOnchange(onchange);
140     }
141     if (suggestMethod != null) {
142       inTag.setSuggestMethod(suggestMethod);
143     }
144     if (disabled != null) {
145       inTag.setDisabled(disabled);
146     }
147     if (focus != null) {
148       inTag.setFocus(focus);
149     }
150     if (id != null) {
151       inTag.setId(id);
152     }
153     if (password != null) {
154       inTag.setPassword(password);
155     }
156     if (readonly != null) {
157       inTag.setReadonly(readonly);
158     }
159     if (required != null) {
160       inTag.setRequired(required);
161     }
162     if (markup != null) {
163       inTag.setMarkup(markup);
164     }
165     if (tabIndex != null) {
166       inTag.setTabIndex(tabIndex);
167     }
168     if (validatorMessage != null) {
169       inTag.setValidatorMessage(validatorMessage);
170     }
171     if (converterMessage != null) {
172       inTag.setConverterMessage(converterMessage);
173     }
174     if (requiredMessage != null) {
175       inTag.setRequiredMessage(requiredMessage);
176     }
177     inTag.setParent(labelTag);
178     inTag.doStartTag();
179 
180     return super.doStartTag();
181   }
182 
183   @Override
184   public int doEndTag() throws JspException {
185     inTag.doEndTag();
186     labelTag.doEndTag();
187     return super.doEndTag();
188   }
189 
190   @Override
191   public void release() {
192     super.release();
193     binding = null;
194     converter = null;
195     validator = null;
196     disabled = null;
197     labelWidth = null;
198     focus = null;
199     label = null;
200     password = null;
201     readonly = null;
202     rendered = null;
203     required = null;
204     tip = null;
205     value = null;
206     valueChangeListener = null;
207     onchange = null;
208     suggestMethod = null;
209     markup = null;
210     tabIndex = null;
211     inTag = null;
212     labelTag = null;
213     validatorMessage = null;
214     converterMessage = null;
215     requiredMessage = null;
216   }
217 
218   public void setMarkup(String markup) {
219     this.markup = markup;
220   }
221 
222   public void setValue(String value) {
223     this.value = value;
224   }
225 
226   public void setValueChangeListener(String valueChangeListener) {
227     this.valueChangeListener = valueChangeListener;
228   }
229 
230   public void setLabel(String label) {
231     this.label = label;
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 setOnchange(String onchange) {
251     this.onchange = onchange;
252   }
253 
254   public void setSuggestMethod(String suggestMethod) {
255     this.suggestMethod = suggestMethod;
256   }
257 
258   public void setValidator(String validator) {
259     this.validator = validator;
260   }
261 
262   public void setPassword(String password) {
263     this.password = password;
264   }
265 
266   public void setReadonly(String readonly) {
267     this.readonly = readonly;
268   }
269 
270   public void setDisabled(String disabled) {
271     this.disabled = disabled;
272   }
273 
274   public void setRequired(String required) {
275     this.required = required;
276   }
277 
278   public void setTip(String tip) {
279     this.tip = tip;
280   }
281 
282   public void setLabelWidth(String labelWidth) {
283     this.labelWidth = labelWidth;
284   }
285 
286   public void setTabIndex(String tabIndex) {
287     this.tabIndex = tabIndex;
288   }
289 
290   public void setValidatorMessage(String validatorMessage) {
291     this.validatorMessage = validatorMessage;
292   }
293 
294   public void setConverterMessage(String converterMessage) {
295     this.converterMessage = converterMessage;
296   }
297 
298   public void setRequiredMessage(String requiredMessage) {
299     this.requiredMessage = requiredMessage;
300   }
301 }