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