1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.util; |
17 | |
|
18 | |
import java.lang.reflect.Array; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import javax.faces.FacesException; |
22 | |
import javax.faces.component.UIComponent; |
23 | |
import javax.faces.context.FacesContext; |
24 | |
import javax.faces.convert.Converter; |
25 | |
|
26 | |
import org.seasar.framework.log.Logger; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | 0 | public class UIValueUtil { |
32 | |
|
33 | 2 | private static Logger logger_ = Logger.getLogger(UIValueUtil.class); |
34 | |
|
35 | |
public static String getValueAsString(FacesContext context, |
36 | |
UIComponent component, Object value, Converter converter) { |
37 | 273 | if (converter == null && value != null) { |
38 | 208 | if (value instanceof String) { |
39 | 208 | return (String) value; |
40 | |
} |
41 | |
try { |
42 | 0 | converter = context.getApplication().createConverter( |
43 | |
value.getClass()); |
44 | 0 | } catch (FacesException ex) { |
45 | 0 | logger_.log(ex); |
46 | 0 | } |
47 | |
} |
48 | 65 | if (converter == null) { |
49 | 61 | if (value == null) { |
50 | 61 | return ""; |
51 | |
} |
52 | 0 | return value.toString(); |
53 | |
} |
54 | 4 | return converter.getAsString(context, component, value); |
55 | |
} |
56 | |
|
57 | |
public static final boolean isManyEmpty(Object value) { |
58 | 3 | return value == null |
59 | |
|| (value.getClass().isArray() && Array.getLength(value) == 0) |
60 | |
|| ((value instanceof List) && ((List) value).isEmpty()); |
61 | |
} |
62 | |
|
63 | |
} |