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.util.Iterator; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import javax.faces.component.UIComponent; |
22 | |
import javax.faces.component.UIParameter; |
23 | |
import javax.faces.context.FacesContext; |
24 | |
|
25 | |
import org.seasar.framework.beans.BeanDesc; |
26 | |
import org.seasar.framework.beans.PropertyDesc; |
27 | |
import org.seasar.framework.beans.factory.BeanDescFactory; |
28 | |
import org.seasar.framework.util.AssertionUtil; |
29 | |
|
30 | |
public class UIParameterUtil { |
31 | |
|
32 | 0 | private UIParameterUtil() { |
33 | 0 | } |
34 | |
|
35 | |
public static void saveParametersToRequest(UIComponent component, |
36 | |
FacesContext context) { |
37 | 1 | List children = component.getChildren(); |
38 | 3 | for (int i = 0; i < children.size(); ++i) { |
39 | 2 | Object o = (UIComponent) children.get(i); |
40 | 2 | if (o instanceof UIParameter) { |
41 | 2 | UIParameter param = (UIParameter) o; |
42 | 2 | context.getExternalContext().getRequestMap().put( |
43 | |
param.getName(), param.getValue()); |
44 | |
} |
45 | |
} |
46 | 1 | } |
47 | |
|
48 | |
public static void saveParametersToInstance(UIComponent component, |
49 | |
Object obj) { |
50 | 1 | AssertionUtil.assertNotNull("component", component); |
51 | 1 | AssertionUtil.assertNotNull("obj", obj); |
52 | 1 | for (Iterator itr = component.getChildren().iterator(); itr.hasNext();) { |
53 | 2 | Object o = itr.next(); |
54 | 2 | if (o instanceof UIParameter) { |
55 | 2 | UIParameter param = (UIParameter) o; |
56 | 2 | String name = param.getName(); |
57 | 2 | Object value = param.getValue(); |
58 | 2 | BeanDesc beanDesc = BeanDescFactory.getBeanDesc(obj.getClass()); |
59 | 2 | if (beanDesc.hasPropertyDesc(name)) { |
60 | 2 | PropertyDesc propertyDesc = beanDesc.getPropertyDesc(name); |
61 | 2 | if (propertyDesc.isWritable()) { |
62 | 2 | propertyDesc.setValue(obj, value); |
63 | |
} |
64 | |
} |
65 | |
} |
66 | |
} |
67 | 1 | } |
68 | |
|
69 | |
} |