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