1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package javax.faces.component.html;
20
21 import javax.faces.component.UIInput;
22 import javax.faces.context.FacesContext;
23
24 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
25 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
26
27
28
29
30
31 @JSFComponent
32 (name = "h:inputFile",
33 clazz = "javax.faces.component.html.HtmlInputFile",template=true,
34 tagClass = "org.apache.myfaces.taglib.html.HtmlInputFileTag",
35 defaultRendererType = "javax.faces.File",
36 implementz = "javax.faces.component.behavior.ClientBehaviorHolder",
37 defaultEventName = "valueChange"
38 )
39 abstract class _HtmlInputFile extends UIInput
40 implements _AccesskeyProperty,
41 _AltProperty, _UniversalProperties, _DisabledReadonlyProperties,
42 _FocusBlurProperties, _ChangeSelectProperties, _EventProperties,
43 _StyleProperties, _TabindexProperty, _LabelProperty, _RoleProperty
44 {
45
46 static public final String COMPONENT_FAMILY =
47 "javax.faces.Input";
48 static public final String COMPONENT_TYPE =
49 "javax.faces.HtmlInputFile";
50
51
52
53
54
55
56
57 public abstract int getMaxlength();
58
59
60
61
62
63
64
65 public abstract int getSize();
66
67
68
69
70
71
72
73
74
75 @JSFProperty
76 public abstract String getAutocomplete();
77
78 protected void validateValue(FacesContext context, Object convertedValue)
79 {
80 if (!isValid())
81 {
82 return;
83 }
84
85
86 boolean isEmpty = isEmptyValue(convertedValue);
87
88 if (isRequired() && isEmpty)
89 {
90 if (getRequiredMessage() != null)
91 {
92 String requiredMessage = getRequiredMessage();
93 context.addMessage(this.getClientId(context), new javax.faces.application.FacesMessage(
94 javax.faces.application.FacesMessage.SEVERITY_ERROR,
95 requiredMessage, requiredMessage));
96 }
97 else
98 {
99 _MessageUtils.addErrorMessage(context, this, REQUIRED_MESSAGE_ID,
100 new Object[] { _MessageUtils.getLabel(context, this) });
101 }
102 setValid(false);
103 return;
104 }
105
106 if (!isEmpty)
107 {
108 super.validateValue(context, convertedValue);
109 }
110 }
111
112 private static boolean isEmptyValue(Object value)
113 {
114 if (value == null)
115 {
116 return true;
117 }
118 else if (value instanceof String)
119 {
120 if ( ((String)value).trim().length() <= 0 )
121 {
122 return true;
123 }
124 }
125 else if (value instanceof java.util.Collection)
126 {
127 if ( ((java.util.Collection)value).isEmpty())
128 {
129 return true;
130 }
131 }
132 else if (value.getClass().isArray())
133 {
134 if (java.lang.reflect.Array.getLength(value) <= 0)
135 {
136 return true;
137 }
138 }
139 else if (value instanceof java.util.Map)
140 {
141 if ( ((java.util.Map)value).isEmpty())
142 {
143 return true;
144 }
145 }
146 else if (value instanceof javax.servlet.http.Part)
147 {
148 if (((javax.servlet.http.Part)value).getSize() <= 0)
149 {
150 return true;
151 }
152 }
153 return false;
154 }
155
156 }