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 | 0 | 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 | 0 | if (!isValid()) |
81 | |
{ |
82 | 0 | return; |
83 | |
} |
84 | |
|
85 | |
|
86 | 0 | boolean isEmpty = isEmptyValue(convertedValue); |
87 | |
|
88 | 0 | if (isRequired() && isEmpty) |
89 | |
{ |
90 | 0 | if (getRequiredMessage() != null) |
91 | |
{ |
92 | 0 | String requiredMessage = getRequiredMessage(); |
93 | 0 | context.addMessage(this.getClientId(context), new javax.faces.application.FacesMessage( |
94 | |
javax.faces.application.FacesMessage.SEVERITY_ERROR, |
95 | |
requiredMessage, requiredMessage)); |
96 | 0 | } |
97 | |
else |
98 | |
{ |
99 | 0 | _MessageUtils.addErrorMessage(context, this, REQUIRED_MESSAGE_ID, |
100 | |
new Object[] { _MessageUtils.getLabel(context, this) }); |
101 | |
} |
102 | 0 | setValid(false); |
103 | 0 | return; |
104 | |
} |
105 | |
|
106 | 0 | if (!isEmpty) |
107 | |
{ |
108 | 0 | super.validateValue(context, convertedValue); |
109 | |
} |
110 | 0 | } |
111 | |
|
112 | |
private static boolean isEmptyValue(Object value) |
113 | |
{ |
114 | 0 | if (value == null) |
115 | |
{ |
116 | 0 | return true; |
117 | |
} |
118 | 0 | else if (value instanceof String) |
119 | |
{ |
120 | 0 | if ( ((String)value).trim().length() <= 0 ) |
121 | |
{ |
122 | 0 | return true; |
123 | |
} |
124 | |
} |
125 | 0 | else if (value instanceof java.util.Collection) |
126 | |
{ |
127 | 0 | if ( ((java.util.Collection)value).isEmpty()) |
128 | |
{ |
129 | 0 | return true; |
130 | |
} |
131 | |
} |
132 | 0 | else if (value.getClass().isArray()) |
133 | |
{ |
134 | 0 | if (java.lang.reflect.Array.getLength(value) <= 0) |
135 | |
{ |
136 | 0 | return true; |
137 | |
} |
138 | |
} |
139 | 0 | else if (value instanceof java.util.Map) |
140 | |
{ |
141 | 0 | if ( ((java.util.Map)value).isEmpty()) |
142 | |
{ |
143 | 0 | return true; |
144 | |
} |
145 | |
} |
146 | 0 | else if (value instanceof javax.servlet.http.Part) |
147 | |
{ |
148 | 0 | if (((javax.servlet.http.Part)value).getSize() <= 0) |
149 | |
{ |
150 | 0 | return true; |
151 | |
} |
152 | |
} |
153 | 0 | return false; |
154 | |
} |
155 | |
|
156 | |
} |