1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.uruma.binding.value.binder; |
17 | |
|
18 | |
import org.seasar.framework.beans.BeanDesc; |
19 | |
import org.seasar.framework.beans.PropertyDesc; |
20 | |
import org.seasar.framework.beans.factory.BeanDescFactory; |
21 | |
import org.seasar.uruma.binding.value.ValueBinder; |
22 | |
import org.seasar.uruma.component.UIComponent; |
23 | |
import org.seasar.uruma.util.AssertionUtil; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public class GenericValueBinder<WIDGET_TYPE> extends |
33 | |
AbstractValueBinder<WIDGET_TYPE> { |
34 | |
private PropertyDesc propertyDesc; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public GenericValueBinder(final Class<WIDGET_TYPE> targetClass, |
45 | |
final String propertyName) { |
46 | 20 | super(targetClass); |
47 | 20 | AssertionUtil.assertNotEmpty("propertyName", propertyName); |
48 | |
|
49 | 20 | BeanDesc beanDesc = BeanDescFactory.getBeanDesc(targetClass); |
50 | 20 | this.propertyDesc = beanDesc.getPropertyDesc(propertyName); |
51 | 20 | } |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
@Override |
58 | |
public void doImportValue(final WIDGET_TYPE widget, final Object formObj, |
59 | |
final PropertyDesc propDesc, final UIComponent uiComp) { |
60 | 0 | Object value = propertyDesc.getValue(widget); |
61 | |
|
62 | |
|
63 | 0 | if (value instanceof String && ((String) value).length() == 0) { |
64 | 0 | value = null; |
65 | |
} |
66 | |
|
67 | 0 | logBinding(IMPORT_VALUE, widget, propertyDesc, formObj, propDesc, value); |
68 | |
|
69 | 0 | propDesc.setValue(formObj, value); |
70 | 0 | } |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
@Override |
77 | |
public void doExportValue(final WIDGET_TYPE widget, final Object formObj, |
78 | |
final PropertyDesc propDesc, final UIComponent uiComp) { |
79 | 0 | Object value = propDesc.getValue(formObj); |
80 | |
|
81 | 0 | if (value == null) { |
82 | 0 | value = ""; |
83 | |
} |
84 | |
|
85 | 0 | logBinding(EXPORT_VALUE, formObj, propDesc, widget, propertyDesc, value); |
86 | |
|
87 | 0 | propertyDesc.setValue(widget, value); |
88 | 0 | } |
89 | |
} |