View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.taglib.extension;
21  
22  import org.apache.myfaces.tobago.apt.annotation.DynamicExpression;
23  import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
24  import org.apache.myfaces.tobago.apt.annotation.Tag;
25  import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
26  import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
27  import org.apache.myfaces.tobago.internal.taglib.TextareaTag;
28  
29  import javax.servlet.jsp.JspException;
30  
31  /**
32   * Renders a multi line text input control with a label.
33   * <br />
34   * Short syntax of:
35   * <p/>
36   * <pre>
37   * &lt;tc:panel>
38   *   &lt;f:facet name="layout">
39   *     &lt;tc:gridLayout columns="auto;*"/>
40   *   &lt;/f:facet>
41   *   &lt;tc:label value="#{label}" for="@auto"/>
42   *   &lt;tc:textarea value="#{value}">
43   *     ...
44   *   &lt;/tc:in>
45   * &lt;/tc:panel>
46   * </pre>
47   */
48  
49  @Tag(name = "textarea")
50  @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.internal.taglib.TextareaTag")
51  public class TextareaExtensionTag extends TobagoExtensionBodyTagSupport {
52  
53    private javax.el.ValueExpression binding;
54    private javax.el.ValueExpression converter;
55    private javax.el.ValueExpression disabled;
56    private javax.el.ValueExpression focus;
57    private javax.el.ValueExpression label;
58    private javax.el.ValueExpression readonly;
59    private javax.el.ValueExpression rendered;
60    private javax.el.ValueExpression required;
61    private javax.el.ValueExpression tip;
62    private javax.el.ValueExpression value;
63    private javax.el.MethodExpression valueChangeListener;
64    private javax.el.MethodExpression validator;
65    private javax.el.ValueExpression onchange;
66    private javax.el.ValueExpression markup;
67    private javax.el.ValueExpression labelWidth;
68    private javax.el.ValueExpression tabIndex;
69    private javax.el.ValueExpression validatorMessage;
70    private javax.el.ValueExpression converterMessage;
71    private javax.el.ValueExpression requiredMessage;
72    private String fieldId;
73  
74    private LabelExtensionTag labelTag;
75    private TextareaTag textareaTag;
76  
77    @Override
78    public int doStartTag() throws JspException {
79  
80      labelTag = new LabelExtensionTag();
81      labelTag.setPageContext(pageContext);
82      labelTag.setRows("*");
83      if (id != null) {
84        labelTag.setId(id);
85      }
86      if (label != null) {
87        labelTag.setValue(label);
88      }
89      if (tip != null) {
90        labelTag.setTip(tip);
91      }
92      if (rendered != null) {
93        labelTag.setRendered(rendered);
94      }
95      if (labelWidth != null) {
96        labelTag.setColumns(createStringValueExpression(labelWidth.getExpressionString() + ";*"));
97      }
98      if (markup != null) {
99        labelTag.setMarkup(markup);
100     }
101     labelTag.setParent(getParent());
102     labelTag.setJspId(nextJspId());
103     labelTag.doStartTag();
104 
105     textareaTag = new TextareaTag();
106     textareaTag.setPageContext(pageContext);
107     if (value != null) {
108       textareaTag.setValue(value);
109     }
110     if (valueChangeListener != null) {
111       textareaTag.setValueChangeListener(valueChangeListener);
112     }
113     if (binding != null) {
114       textareaTag.setBinding(binding);
115     }
116     if (converter != null) {
117       textareaTag.setConverter(converter);
118     }
119     if (validator != null) {
120       textareaTag.setValidator(validator);
121     }
122     if (onchange != null) {
123       textareaTag.setOnchange(onchange);
124     }
125     if (disabled != null) {
126       textareaTag.setDisabled(disabled);
127     }
128     if (focus != null) {
129       textareaTag.setFocus(focus);
130     }
131     if (fieldId != null) {
132       textareaTag.setId(fieldId);
133     }
134     if (label != null) {
135       textareaTag.setLabel(label);
136     }
137     if (readonly != null) {
138       textareaTag.setReadonly(readonly);
139     }
140     if (required != null) {
141       textareaTag.setRequired(required);
142     }
143     if (markup != null) {
144       textareaTag.setMarkup(markup);
145     }
146     if (tabIndex != null) {
147       textareaTag.setTabIndex(tabIndex);
148     }
149     if (validatorMessage != null) {
150       textareaTag.setValidatorMessage(validatorMessage);
151     }
152     if (converterMessage != null) {
153       textareaTag.setConverterMessage(converterMessage);
154     }
155     if (requiredMessage != null) {
156       textareaTag.setRequiredMessage(requiredMessage);
157     }
158     textareaTag.setParent(labelTag);
159     textareaTag.setJspId(nextJspId());
160     textareaTag.doStartTag();
161 
162     return super.doStartTag();
163   }
164 
165   @Override
166   public int doEndTag() throws JspException {
167     textareaTag.doEndTag();
168     labelTag.doEndTag();
169     return super.doEndTag();
170   }
171 
172   @Override
173   public void release() {
174     super.release();
175     binding = null;
176     converter = null;
177     validator = null;
178     disabled = null;
179     labelWidth = null;
180     focus = null;
181     label = null;
182     readonly = null;
183     rendered = null;
184     required = null;
185     tip = null;
186     value = null;
187     onchange = null;
188     markup = null;
189     valueChangeListener = null;
190     tabIndex = null;
191     textareaTag = null;
192     labelTag = null;
193     validatorMessage = null;
194     converterMessage = null;
195     requiredMessage = null;
196     fieldId = null;
197   }
198 
199   /**
200    * The current value of this component.
201    */
202   @TagAttribute
203   @UIComponentTagAttribute(type = "java.lang.Object")
204   public void setValue(javax.el.ValueExpression value) {
205     this.value = value;
206   }
207 
208   /**
209    * MethodBinding representing a value change listener method
210    * that will be notified when a new value has been set for this input component.
211    * The expression must evaluate to a public method that takes a ValueChangeEvent
212    * parameter, with a return type of void.
213    *
214    * @param valueChangeListener
215    */
216   @TagAttribute
217   @UIComponentTagAttribute(
218           type = {},
219           expression = DynamicExpression.METHOD_EXPRESSION_REQUIRED,
220           methodSignature = "javax.faces.event.ValueChangeEvent")
221   public void setValueChangeListener(javax.el.MethodExpression valueChangeListener) {
222     this.valueChangeListener = valueChangeListener;
223   }
224 
225   /**
226    * Text value to display as label.
227    * If text contains an underscore the next character is used as accesskey.
228    */
229   @TagAttribute
230   @UIComponentTagAttribute()
231   public void setLabel(javax.el.ValueExpression label) {
232     this.label = label;
233   }
234 
235   /**
236    * Flag indicating this component should receive the focus.
237    */
238   @TagAttribute
239   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
240   public void setFocus(javax.el.ValueExpression focus) {
241     this.focus = focus;
242   }
243 
244   /**
245    * The value binding expression linking this
246    * component to a property in a backing bean.
247    */
248   @TagAttribute
249   @UIComponentTagAttribute(type = "javax.faces.component.UIComponent")
250   public void setBinding(javax.el.ValueExpression binding) {
251     this.binding = binding;
252   }
253 
254   /**
255    * Flag indicating whether or not this component should be rendered
256    * (during Render Response Phase), or processed on any subsequent form submit.
257    */
258   @TagAttribute
259   @UIComponentTagAttribute(type = "boolean", defaultValue = "true")
260   public void setRendered(javax.el.ValueExpression rendered) {
261     this.rendered = rendered;
262   }
263 
264   /**
265    * An expression that specifies the Converter for this component.
266    * If the value binding expression is a String,
267    * the String is used as an ID to look up a Converter.
268    * If the value binding expression is a Converter,
269    * uses that instance as the converter.
270    * The value can either be a static value (ID case only)
271    * or an EL expression.
272    */
273   @TagAttribute
274   @UIComponentTagAttribute(type = "javax.faces.convert.Converter",
275       expression = DynamicExpression.VALUE_EXPRESSION)
276   public void setConverter(javax.el.ValueExpression converter) {
277     this.converter = converter;
278   }
279 
280   /**
281    * A method binding EL expression,
282    * accepting FacesContext, UIComponent,
283    * and Object parameters, and returning void, that validates
284    * the component's local value.
285    */
286   @TagAttribute
287   @UIComponentTagAttribute(type = {},
288       expression = DynamicExpression.METHOD_EXPRESSION,
289       methodSignature = { "javax.faces.context.FacesContext", "javax.faces.component.UIComponent", "java.lang.Object" })
290   public void setValidator(javax.el.MethodExpression validator) {
291     this.validator = validator;
292   }
293 
294   /**
295    * Clientside script function to add to this component's onchange handler.
296    */
297   @TagAttribute
298   @UIComponentTagAttribute()
299   public void setOnchange(javax.el.ValueExpression onchange) {
300     this.onchange = onchange;
301   }
302 
303   /**
304    * Indicate markup of this component.
305    * Possible value is 'none'. But this can be overridden in the theme.
306    */
307   @TagAttribute
308   @UIComponentTagAttribute(defaultValue = "none", type = "java.lang.String[]")
309   public void setMarkup(javax.el.ValueExpression markup) {
310     this.markup = markup;
311   }
312 
313   /**
314    * Flag indicating that this component will prohibit changes by the user.
315    */
316   @TagAttribute
317   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
318   public void setReadonly(javax.el.ValueExpression readonly) {
319     this.readonly = readonly;
320   }
321 
322   /**
323    * Flag indicating that this element is disabled.
324    */
325   @TagAttribute()
326   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
327   public void setDisabled(javax.el.ValueExpression disabled) {
328     this.disabled = disabled;
329   }
330 
331   /**
332    * Flag indicating that a value is required.
333    * If the value is an empty string a
334    * ValidationError occurs and a Error Message is rendered.
335    */
336   @TagAttribute
337   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
338   public void setRequired(javax.el.ValueExpression required) {
339     this.required = required;
340   }
341 
342   /**
343    * Text value to display as tooltip.
344    */
345   @TagAttribute
346   @UIComponentTagAttribute()
347   public void setTip(javax.el.ValueExpression tip) {
348     this.tip = tip;
349   }
350 
351    /**
352    * The width for the label component. Default: 'auto'.
353    * This value is used in the gridLayouts columns attribute.
354    * See gridLayout tag for valid values.
355    */
356   @TagAttribute
357   @UIComponentTagAttribute()
358   public void setLabelWidth(javax.el.ValueExpression labelWidth) {
359     this.labelWidth = labelWidth;
360   }
361 
362   @TagAttribute
363   @UIComponentTagAttribute(type = "java.lang.Integer")
364   public void setTabIndex(javax.el.ValueExpression tabIndex) {
365     this.tabIndex = tabIndex;
366   }
367 
368   /**
369    * An expression that specifies the validator message
370    */
371   @TagAttribute
372   @UIComponentTagAttribute()
373   public void setValidatorMessage(javax.el.ValueExpression validatorMessage) {
374     this.validatorMessage = validatorMessage;
375   }
376 
377   /**
378    * An expression that specifies the converter message
379    */
380   @TagAttribute
381   @UIComponentTagAttribute()
382   public void setConverterMessage(javax.el.ValueExpression converterMessage) {
383     this.converterMessage = converterMessage;
384   }
385 
386   /**
387    * An expression that specifies the required message
388    */
389   @TagAttribute
390   @UIComponentTagAttribute()
391   public void setRequiredMessage(javax.el.ValueExpression requiredMessage) {
392     this.requiredMessage = requiredMessage;
393   }
394 
395   /**
396    * The component identifier for the input field component inside of the container.
397    * This value must be unique within the closest parent component that is a naming container.
398    */
399   @TagAttribute(rtexprvalue = true)
400   @UIComponentTagAttribute
401   public void setFieldId(String fieldId) {
402     this.fieldId = fieldId;
403   }
404 
405   /**
406    * The component identifier for this component.
407    * This value must be unique within the closest parent component that is a naming container.
408    * For tx components the id will be set to the container (e. g. the panel).
409    * To set the id of the input field, you have to use the attribute "fieldId".
410    */
411   @TagAttribute(rtexprvalue = true)
412   @UIComponentTagAttribute
413   public void setId(String id) {
414     super.setId(id);
415   }
416 }