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