View Javadoc

1   package org.apache.myfaces.tobago.taglib.extension12;
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.apt.annotation.TagAttribute;
23  import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
24  import org.apache.myfaces.tobago.apt.annotation.DynamicExpression;
25  import org.apache.myfaces.tobago.internal.taglib.TextareaTag;
26  
27  import javax.servlet.jsp.JspException;
28  
29  /**
30   * Renders a multiline text input control with a label.
31   * <br />
32   * Short syntax of:
33   * <p/>
34   * <pre>
35   * &lt;tc:panel>
36   *   &lt;f:facet name="layout">
37   *     &lt;tc:gridLayout columns="fixed;*"/>
38   *   &lt;/f:facet>
39   *   &lt;tc:label value="#{label}" for="@auto"/>
40   *   &lt;tc:textarea value="#{value}">
41   *     ...
42   *   &lt;/tc:in>
43   * &lt;/tc:panel>
44   * </pre>
45   */
46  
47  @Tag(name = "textarea")
48  @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.internal.taglib.TextAreaTag")
49  public class TextAreaExtensionTag extends TobagoExtensionBodyTagSupport {
50  
51    private javax.el.ValueExpression binding;
52    private javax.el.ValueExpression converter;
53    private javax.el.ValueExpression disabled;
54    private javax.el.ValueExpression focus;
55    private javax.el.ValueExpression label;
56    private javax.el.ValueExpression readonly;
57    private javax.el.ValueExpression rendered;
58    private javax.el.ValueExpression required;
59    private javax.el.ValueExpression tip;
60    private javax.el.ValueExpression value;
61    private javax.el.MethodExpression valueChangeListener;
62    private javax.el.MethodExpression validator;
63    private javax.el.ValueExpression onchange;
64    private javax.el.ValueExpression markup;
65    private javax.el.ValueExpression labelWidth;
66    private javax.el.ValueExpression tabIndex;
67    private javax.el.ValueExpression validatorMessage;
68    private javax.el.ValueExpression converterMessage;
69    private javax.el.ValueExpression requiredMessage;
70  
71    private LabelExtensionTag labelTag;
72    private TextareaTag textAreaTag;
73  
74    @Override
75    public int doStartTag() throws JspException {
76  
77      labelTag = new LabelExtensionTag();
78      labelTag.setPageContext(pageContext);
79      labelTag.setRows("*");
80      if (label != null) {
81        labelTag.setValue(label);
82      }
83      if (tip != null) {
84        labelTag.setTip(tip);
85      }
86      if (rendered != null) {
87        labelTag.setRendered(rendered);
88      }
89      if (labelWidth != null) {
90        labelTag.setColumns(createStringValueExpression(labelWidth.getExpressionString() + ";*"));
91      }
92      if (markup != null) {
93        labelTag.setMarkup(markup);
94      }
95      labelTag.setParent(getParent());
96      labelTag.doStartTag();
97  
98      textAreaTag = new TextareaTag();
99      textAreaTag.setPageContext(pageContext);
100     if (value != null) {
101       textAreaTag.setValue(value);
102     }
103     if (valueChangeListener != null) {
104       textAreaTag.setValueChangeListener(valueChangeListener);
105     }
106     if (binding != null) {
107       textAreaTag.setBinding(binding);
108     }
109     if (converter != null) {
110       textAreaTag.setConverter(converter);
111     }
112     if (validator != null) {
113       textAreaTag.setValidator(validator);
114     }
115     if (onchange != null) {
116       textAreaTag.setOnchange(onchange);
117     }
118     if (disabled != null) {
119       textAreaTag.setDisabled(disabled);
120     }
121     if (focus != null) {
122       textAreaTag.setFocus(focus);
123     }
124     if (id != null) {
125       textAreaTag.setId(id);
126     }
127     if (readonly != null) {
128       textAreaTag.setReadonly(readonly);
129     }
130     if (required != null) {
131       textAreaTag.setRequired(required);
132     }
133     if (markup != null) {
134       textAreaTag.setMarkup(markup);
135     }
136     if (tabIndex != null) {
137       textAreaTag.setTabIndex(tabIndex);
138     }
139     if (validatorMessage != null) {
140       textAreaTag.setValidatorMessage(validatorMessage);
141     }
142     if (converterMessage != null) {
143       textAreaTag.setConverterMessage(converterMessage);
144     }
145     if (requiredMessage != null) {
146       textAreaTag.setRequiredMessage(requiredMessage);
147     }
148     textAreaTag.setParent(labelTag);
149     textAreaTag.doStartTag();
150 
151     return super.doStartTag();
152   }
153 
154   @Override
155   public int doEndTag() throws JspException {
156     textAreaTag.doEndTag();
157     labelTag.doEndTag();
158     return super.doEndTag();
159   }
160 
161   @Override
162   public void release() {
163     super.release();
164     binding = null;
165     converter = null;
166     validator = null;
167     disabled = null;
168     labelWidth = null;
169     focus = null;
170     label = null;
171     readonly = null;
172     rendered = null;
173     required = null;
174     tip = null;
175     value = null;
176     onchange = null;
177     markup = null;
178     valueChangeListener = null;
179     tabIndex = null;
180     textAreaTag = null;
181     labelTag = null;
182     validatorMessage = null;
183     converterMessage = null;
184     requiredMessage = null;
185   }
186 
187   /**
188    * The current value of this component.
189    */
190   @TagAttribute
191   @UIComponentTagAttribute(type = "java.lang.Object")
192   public void setValue(javax.el.ValueExpression value) {
193     this.value = value;
194   }
195 
196   /**
197    * MethodBinding representing a value change listener method
198    * that will be notified when a new value has been set for this input component.
199    * The expression must evaluate to a public method that takes a ValueChangeEvent
200    * parameter, with a return type of void.
201    *
202    * @param valueChangeListener
203    */
204   @TagAttribute
205   @UIComponentTagAttribute(
206           type = {},
207           expression = DynamicExpression.METHOD_BINDING_REQUIRED,
208           methodSignature = "javax.faces.event.ValueChangeEvent")
209   public void setValueChangeListener(javax.el.MethodExpression valueChangeListener) {
210     this.valueChangeListener = valueChangeListener;
211   }
212 
213   /**
214    * Text value to display as label.
215    * If text contains an underscore the next character is used as accesskey.
216    */
217   @TagAttribute
218   @UIComponentTagAttribute()
219   public void setLabel(javax.el.ValueExpression label) {
220     this.label = label;
221   }
222 
223   /**
224    * Flag indicating this component should recieve the focus.
225    */
226   @TagAttribute
227   @UIComponentTagAttribute(type = "java.lang.Boolean")
228   public void setFocus(javax.el.ValueExpression focus) {
229     this.focus = focus;
230   }
231 
232   /**
233    * The value binding expression linking this
234    * component to a property in a backing bean.
235    */
236   @TagAttribute
237   @UIComponentTagAttribute(type = "javax.faces.component.UIComponent")
238   public void setBinding(javax.el.ValueExpression binding) {
239     this.binding = binding;
240   }
241 
242   /**
243    * Flag indicating whether or not this component should be rendered
244    * (during Render Response Phase), or processed on any subsequent form submit.
245    */
246   @TagAttribute
247   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "true")
248   public void setRendered(javax.el.ValueExpression rendered) {
249     this.rendered = rendered;
250   }
251 
252   /**
253    * An expression that specifies the Converter for this component.
254    * If the value binding expression is a String,
255    * the String is used as an ID to look up a Converter.
256    * If the value binding expression is a Converter,
257    * uses that instance as the converter.
258    * The value can either be a static value (ID case only)
259    * or an EL expression.
260    */
261   @TagAttribute
262   @UIComponentTagAttribute(type = "javax.faces.convert.Converter",
263       expression = DynamicExpression.VALUE_BINDING)
264   public void setConverter(javax.el.ValueExpression converter) {
265     this.converter = converter;
266   }
267 
268   /**
269    * A method binding EL expression,
270    * accepting FacesContext, UIComponent,
271    * and Object parameters, and returning void, that validates
272    * the component's local value.
273    */
274   @TagAttribute
275   @UIComponentTagAttribute(type = {},
276       expression = DynamicExpression.METHOD_BINDING,
277       methodSignature = { "javax.faces.context.FacesContext", "javax.faces.component.UIComponent", "java.lang.Object" })
278   public void setValidator(javax.el.MethodExpression validator) {
279     this.validator = validator;
280   }
281 
282   /**
283    * Clientside script function to add to this component's onchange handler.
284    */
285   @TagAttribute
286   @UIComponentTagAttribute()
287   public void setOnchange(javax.el.ValueExpression onchange) {
288     this.onchange = onchange;
289   }
290 
291   /**
292    * Indicate markup of this component.
293    * Possible value is 'none'. But this can be overridden in the theme.
294    */
295   @TagAttribute
296   @UIComponentTagAttribute(defaultValue = "none", type = "java.lang.String[]")
297   public void setMarkup(javax.el.ValueExpression markup) {
298     this.markup = markup;
299   }
300 
301   /**
302    * Flag indicating that this component will prohibit changes by the user.
303    */
304   @TagAttribute
305   @UIComponentTagAttribute(type = "java.lang.Boolean")
306   public void setReadonly(javax.el.ValueExpression readonly) {
307     this.readonly = readonly;
308   }
309 
310   /**
311    * Flag indicating that this element is disabled.
312    */
313   @TagAttribute()
314   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "false")
315   public void setDisabled(javax.el.ValueExpression disabled) {
316     this.disabled = disabled;
317   }
318 
319   /**
320    * Flag indicating that a value is required.
321    * If the value is an empty string a
322    * ValidationError occurs and a Error Message is rendered.
323    */
324   @TagAttribute
325   @UIComponentTagAttribute(type = "java.lang.Boolean")
326   public void setRequired(javax.el.ValueExpression required) {
327     this.required = required;
328   }
329 
330   /**
331    * Text value to display as tooltip.
332    */
333   @TagAttribute
334   @UIComponentTagAttribute()
335   public void setTip(javax.el.ValueExpression tip) {
336     this.tip = tip;
337   }
338 
339    /**
340    * The width for the label component. Default: 'fixed'.
341    * This value is used in the gridLayouts columns attribute.
342    * See gridLayout tag for valid values.
343    */
344   @TagAttribute
345   @UIComponentTagAttribute()
346   public void setLabelWidth(javax.el.ValueExpression labelWidth) {
347     this.labelWidth = labelWidth;
348   }
349 
350   @TagAttribute
351   @UIComponentTagAttribute(type = "java.lang.Integer")
352   public void setTabIndex(javax.el.ValueExpression tabIndex) {
353     this.tabIndex = tabIndex;
354   }
355 
356   /**
357    * An expression that specifies the validator message
358    */
359   @TagAttribute
360   @UIComponentTagAttribute()
361   public void setValidatorMessage(javax.el.ValueExpression validatorMessage) {
362     this.validatorMessage = validatorMessage;
363   }
364 
365   /**
366    * An expression that specifies the converter message
367    */
368   @TagAttribute
369   @UIComponentTagAttribute()
370   public void setConverterMessage(javax.el.ValueExpression converterMessage) {
371     this.converterMessage = converterMessage;
372   }
373 
374   /**
375    * An expression that specifies the required message
376    */
377   @TagAttribute
378   @UIComponentTagAttribute()
379   public void setRequiredMessage(javax.el.ValueExpression requiredMessage) {
380     this.requiredMessage = requiredMessage;
381   }
382 
383 }