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