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  package javax.faces.component.html;
20  
21  import javax.faces.el.ValueBinding;
22  import javax.el.ValueExpression;
23  import javax.faces.context.FacesContext;
24  import javax.faces.component.UIComponent;
25  import javax.faces.convert.Converter;
26  import javax.faces.el.MethodBinding;
27  
28  
29  // Generated from class javax.faces.component.html._HtmlInputFile.
30  //
31  // WARNING: This file was automatically generated. Do not edit it directly,
32  //          or you will lose your changes.
33  public class HtmlInputFile extends javax.faces.component.UIInput
34      implements javax.faces.component.behavior.ClientBehaviorHolder
35  {
36  
37      static public final String COMPONENT_FAMILY =
38          "javax.faces.Input";
39      static public final String COMPONENT_TYPE =
40          "javax.faces.HtmlInputFile";
41  
42      //BEGIN CODE COPIED FROM javax.faces.component.html._HtmlInputFile 
43      protected void validateValue(javax.faces.context.FacesContext context, java.lang.Object convertedValue)
44      {
45          if (!isValid())
46          {
47              return;
48          }
49  
50          // If our value is empty, check the required property
51          boolean isEmpty = isEmptyValue(convertedValue); 
52  
53          if (isRequired() && isEmpty)
54          {
55              if (getRequiredMessage() != null)
56              {
57                  String requiredMessage = getRequiredMessage();
58                  context.addMessage(this.getClientId(context), new javax.faces.application.FacesMessage(
59                          javax.faces.application.FacesMessage.SEVERITY_ERROR,
60                      requiredMessage, requiredMessage));
61              }
62              else
63              {
64                  _MessageUtils.addErrorMessage(context, this, REQUIRED_MESSAGE_ID,
65                      new Object[] { _MessageUtils.getLabel(context, this) });
66              }
67              setValid(false);
68              return;
69          }
70  
71          if (!isEmpty)
72          {
73              super.validateValue(context, convertedValue);
74          }
75      }
76  
77      private static boolean isEmptyValue(java.lang.Object value)
78      {
79          if (value == null)
80          {
81              return true;
82          }
83          else if (value instanceof String)
84          {
85              if ( ((String)value).trim().length() <= 0 )
86              {
87                  return true;
88              }
89          }
90          else if (value instanceof java.util.Collection)
91          {
92              if ( ((java.util.Collection)value).isEmpty())
93              {
94                  return true;
95              }
96          }
97          else if (value.getClass().isArray())
98          {
99              if (java.lang.reflect.Array.getLength(value) <= 0)
100             {
101                 return true;
102             }
103         }
104         else if (value instanceof java.util.Map)
105         {
106             if ( ((java.util.Map)value).isEmpty())
107             {
108                 return true;
109             }
110         }
111         else if (value instanceof javax.servlet.http.Part) 
112         {
113             if (((javax.servlet.http.Part)value).getSize() <= 0) 
114             {
115                 return true;
116             }
117         }
118         return false;
119     }
120 
121 
122     //END CODE COPIED FROM javax.faces.component.html._HtmlInputFile
123 
124     public HtmlInputFile()
125     {
126         setRendererType("javax.faces.File");
127     }
128 
129     @Override    
130     public String getFamily()
131     {
132         return COMPONENT_FAMILY;
133     }
134 
135 
136     static private final java.util.Collection<String> CLIENT_EVENTS_LIST = 
137         java.util.Collections.unmodifiableCollection(
138             java.util.Arrays.asList(
139              "blur"
140             , "focus"
141             , "click"
142             , "dblclick"
143             , "keydown"
144             , "keypress"
145             , "keyup"
146             , "mousedown"
147             , "mousemove"
148             , "mouseout"
149             , "mouseover"
150             , "mouseup"
151             , "change"
152             , "select"
153             , "valueChange"
154         ));
155 
156     public java.util.Collection<String> getEventNames()
157     {
158         return CLIENT_EVENTS_LIST;
159     }
160 
161     @Override
162     public void addClientBehavior(String eventName, javax.faces.component.behavior.ClientBehavior behavior)
163     {
164         super.addClientBehavior(eventName, behavior);
165         _CommonEventConstants.markEvent(this, eventName);
166     }
167 
168     //ClientBehaviorHolder default: valueChange
169     public String getDefaultEventName()
170     {
171         return "valueChange";
172     }
173 
174     
175     // Property: maxlength
176 
177     public int getMaxlength()
178     {
179         return (Integer) getStateHelper().eval(PropertyKeys.maxlength, Integer.MIN_VALUE);
180     }
181     
182     public void setMaxlength(int maxlength)
183     {
184         getStateHelper().put(PropertyKeys.maxlength, maxlength ); 
185         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.MAXLENGTH_PROP);
186     }
187     // Property: size
188 
189     public int getSize()
190     {
191         return (Integer) getStateHelper().eval(PropertyKeys.size, Integer.MIN_VALUE);
192     }
193     
194     public void setSize(int size)
195     {
196         getStateHelper().put(PropertyKeys.size, size ); 
197         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.SIZE_PROP);
198     }
199     // Property: autocomplete
200 
201     public String getAutocomplete()
202     {
203         return (String) getStateHelper().eval(PropertyKeys.autocomplete);
204     }
205     
206     public void setAutocomplete(String autocomplete)
207     {
208         getStateHelper().put(PropertyKeys.autocomplete, autocomplete ); 
209     }
210     // Property: label
211 
212     public String getLabel()
213     {
214         return (String) getStateHelper().eval(PropertyKeys.label);
215     }
216     
217     public void setLabel(String label)
218     {
219         getStateHelper().put(PropertyKeys.label, label ); 
220         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.LABEL_PROP);
221     }
222     // Property: style
223 
224     public String getStyle()
225     {
226         return (String) getStateHelper().eval(PropertyKeys.style);
227     }
228     
229     public void setStyle(String style)
230     {
231         getStateHelper().put(PropertyKeys.style, style ); 
232         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.STYLE_PROP);
233     }
234     // Property: styleClass
235 
236     public String getStyleClass()
237     {
238         return (String) getStateHelper().eval(PropertyKeys.styleClass);
239     }
240     
241     public void setStyleClass(String styleClass)
242     {
243         getStateHelper().put(PropertyKeys.styleClass, styleClass ); 
244         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.STYLECLASS_PROP);
245     }
246     // Property: alt
247 
248     public String getAlt()
249     {
250         return (String) getStateHelper().eval(PropertyKeys.alt);
251     }
252     
253     public void setAlt(String alt)
254     {
255         getStateHelper().put(PropertyKeys.alt, alt ); 
256         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ALT_PROP);
257     }
258     // Property: tabindex
259 
260     public String getTabindex()
261     {
262         return (String) getStateHelper().eval(PropertyKeys.tabindex);
263     }
264     
265     public void setTabindex(String tabindex)
266     {
267         getStateHelper().put(PropertyKeys.tabindex, tabindex ); 
268         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.TABINDEX_PROP);
269     }
270     // Property: onblur
271 
272     public String getOnblur()
273     {
274         return (String) getStateHelper().eval(PropertyKeys.onblur);
275     }
276     
277     public void setOnblur(String onblur)
278     {
279         getStateHelper().put(PropertyKeys.onblur, onblur ); 
280         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONBLUR_PROP);
281     }
282     // Property: onfocus
283 
284     public String getOnfocus()
285     {
286         return (String) getStateHelper().eval(PropertyKeys.onfocus);
287     }
288     
289     public void setOnfocus(String onfocus)
290     {
291         getStateHelper().put(PropertyKeys.onfocus, onfocus ); 
292         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONFOCUS_PROP);
293     }
294     // Property: accesskey
295 
296     public String getAccesskey()
297     {
298         return (String) getStateHelper().eval(PropertyKeys.accesskey);
299     }
300     
301     public void setAccesskey(String accesskey)
302     {
303         getStateHelper().put(PropertyKeys.accesskey, accesskey ); 
304         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ACCESSKEY_PROP);
305     }
306     // Property: role
307 
308     public String getRole()
309     {
310         return (String) getStateHelper().eval(PropertyKeys.role);
311     }
312     
313     public void setRole(String role)
314     {
315         getStateHelper().put(PropertyKeys.role, role ); 
316         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ROLE_PROP);
317     }
318     // Property: onclick
319 
320     public String getOnclick()
321     {
322         return (String) getStateHelper().eval(PropertyKeys.onclick);
323     }
324     
325     public void setOnclick(String onclick)
326     {
327         getStateHelper().put(PropertyKeys.onclick, onclick ); 
328         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONCLICK_PROP);
329     }
330     // Property: ondblclick
331 
332     public String getOndblclick()
333     {
334         return (String) getStateHelper().eval(PropertyKeys.ondblclick);
335     }
336     
337     public void setOndblclick(String ondblclick)
338     {
339         getStateHelper().put(PropertyKeys.ondblclick, ondblclick ); 
340         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONDBLCLICK_PROP);
341     }
342     // Property: onkeydown
343 
344     public String getOnkeydown()
345     {
346         return (String) getStateHelper().eval(PropertyKeys.onkeydown);
347     }
348     
349     public void setOnkeydown(String onkeydown)
350     {
351         getStateHelper().put(PropertyKeys.onkeydown, onkeydown ); 
352         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONKEYDOWN_PROP);
353     }
354     // Property: onkeypress
355 
356     public String getOnkeypress()
357     {
358         return (String) getStateHelper().eval(PropertyKeys.onkeypress);
359     }
360     
361     public void setOnkeypress(String onkeypress)
362     {
363         getStateHelper().put(PropertyKeys.onkeypress, onkeypress ); 
364         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONKEYPRESS_PROP);
365     }
366     // Property: onkeyup
367 
368     public String getOnkeyup()
369     {
370         return (String) getStateHelper().eval(PropertyKeys.onkeyup);
371     }
372     
373     public void setOnkeyup(String onkeyup)
374     {
375         getStateHelper().put(PropertyKeys.onkeyup, onkeyup ); 
376         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONKEYUP_PROP);
377     }
378     // Property: onmousedown
379 
380     public String getOnmousedown()
381     {
382         return (String) getStateHelper().eval(PropertyKeys.onmousedown);
383     }
384     
385     public void setOnmousedown(String onmousedown)
386     {
387         getStateHelper().put(PropertyKeys.onmousedown, onmousedown ); 
388         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONMOUSEDOWN_PROP);
389     }
390     // Property: onmousemove
391 
392     public String getOnmousemove()
393     {
394         return (String) getStateHelper().eval(PropertyKeys.onmousemove);
395     }
396     
397     public void setOnmousemove(String onmousemove)
398     {
399         getStateHelper().put(PropertyKeys.onmousemove, onmousemove ); 
400         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONMOUSEMOVE_PROP);
401     }
402     // Property: onmouseout
403 
404     public String getOnmouseout()
405     {
406         return (String) getStateHelper().eval(PropertyKeys.onmouseout);
407     }
408     
409     public void setOnmouseout(String onmouseout)
410     {
411         getStateHelper().put(PropertyKeys.onmouseout, onmouseout ); 
412         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONMOUSEOUT_PROP);
413     }
414     // Property: onmouseover
415 
416     public String getOnmouseover()
417     {
418         return (String) getStateHelper().eval(PropertyKeys.onmouseover);
419     }
420     
421     public void setOnmouseover(String onmouseover)
422     {
423         getStateHelper().put(PropertyKeys.onmouseover, onmouseover ); 
424         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONMOUSEOVER_PROP);
425     }
426     // Property: onmouseup
427 
428     public String getOnmouseup()
429     {
430         return (String) getStateHelper().eval(PropertyKeys.onmouseup);
431     }
432     
433     public void setOnmouseup(String onmouseup)
434     {
435         getStateHelper().put(PropertyKeys.onmouseup, onmouseup ); 
436         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONMOUSEUP_PROP);
437     }
438     // Property: onchange
439 
440     public String getOnchange()
441     {
442         return (String) getStateHelper().eval(PropertyKeys.onchange);
443     }
444     
445     public void setOnchange(String onchange)
446     {
447         getStateHelper().put(PropertyKeys.onchange, onchange ); 
448         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONCHANGE_PROP);
449     }
450     // Property: onselect
451 
452     public String getOnselect()
453     {
454         return (String) getStateHelper().eval(PropertyKeys.onselect);
455     }
456     
457     public void setOnselect(String onselect)
458     {
459         getStateHelper().put(PropertyKeys.onselect, onselect ); 
460         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.ONSELECT_PROP);
461     }
462     // Property: dir
463 
464     public String getDir()
465     {
466         return (String) getStateHelper().eval(PropertyKeys.dir);
467     }
468     
469     public void setDir(String dir)
470     {
471         getStateHelper().put(PropertyKeys.dir, dir ); 
472         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.DIR_PROP);
473     }
474     // Property: lang
475 
476     public String getLang()
477     {
478         return (String) getStateHelper().eval(PropertyKeys.lang);
479     }
480     
481     public void setLang(String lang)
482     {
483         getStateHelper().put(PropertyKeys.lang, lang ); 
484         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.LANG_PROP);
485     }
486     // Property: title
487 
488     public String getTitle()
489     {
490         return (String) getStateHelper().eval(PropertyKeys.title);
491     }
492     
493     public void setTitle(String title)
494     {
495         getStateHelper().put(PropertyKeys.title, title ); 
496         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.TITLE_PROP);
497     }
498     // Property: disabled
499 
500     public boolean isDisabled()
501     {
502         return (Boolean) getStateHelper().eval(PropertyKeys.disabled, false);
503     }
504     
505     public void setDisabled(boolean disabled)
506     {
507         getStateHelper().put(PropertyKeys.disabled, disabled ); 
508         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.DISABLED_PROP);
509     }
510     // Property: readonly
511 
512     public boolean isReadonly()
513     {
514         return (Boolean) getStateHelper().eval(PropertyKeys.readonly, false);
515     }
516     
517     public void setReadonly(boolean readonly)
518     {
519         getStateHelper().put(PropertyKeys.readonly, readonly ); 
520         _CommonPropertyConstants.markProperty(this, _CommonPropertyConstants.READONLY_PROP);
521     }
522 
523     public void setValueBinding(String name, ValueBinding binding)
524     {
525         super.setValueBinding(name, binding);
526         _CommonPropertyConstants.markProperty(this, name);
527     }
528 
529     public void setValueExpression(String name, ValueExpression expression)
530     {
531         super.setValueExpression(name, expression);
532         _CommonPropertyConstants.markProperty(this, name);
533     }
534 
535     protected enum PropertyKeys
536     {
537          maxlength
538         , size
539         , autocomplete
540         , label
541         , style
542         , styleClass
543         , alt
544         , tabindex
545         , onblur
546         , onfocus
547         , accesskey
548         , role
549         , onclick
550         , ondblclick
551         , onkeydown
552         , onkeypress
553         , onkeyup
554         , onmousedown
555         , onmousemove
556         , onmouseout
557         , onmouseover
558         , onmouseup
559         , onchange
560         , onselect
561         , dir
562         , lang
563         , title
564         , disabled
565         , readonly
566     }
567 
568  }