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.Map; |
19 | |
|
20 | |
import javax.faces.component.EditableValueHolder; |
21 | |
import javax.faces.component.UIComponent; |
22 | |
import javax.faces.context.FacesContext; |
23 | |
|
24 | |
import org.seasar.framework.util.AssertionUtil; |
25 | |
import org.seasar.teeda.core.exception.NoEditableValueHolderRuntimeException; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class DecodeUtil { |
32 | |
|
33 | 0 | private DecodeUtil() { |
34 | 0 | } |
35 | |
|
36 | |
public static void decode(FacesContext context, UIComponent component) { |
37 | 5 | AssertionUtil.assertNotNull("context is null.", context); |
38 | 4 | AssertionUtil.assertNotNull("component is null.", component); |
39 | 3 | if (!(component instanceof EditableValueHolder)) { |
40 | 1 | throw new NoEditableValueHolderRuntimeException(component |
41 | |
.getClass()); |
42 | |
} |
43 | 2 | EditableValueHolder evh = (EditableValueHolder) component; |
44 | 2 | Map paramMap = context.getExternalContext().getRequestParameterMap(); |
45 | 2 | String clientId = component.getClientId(context); |
46 | 2 | if (paramMap.containsKey(clientId)) { |
47 | 1 | Object submittedValue = paramMap.get(clientId); |
48 | 1 | evh.setSubmittedValue(submittedValue); |
49 | |
} |
50 | 2 | } |
51 | |
|
52 | |
public static void decodeMany(FacesContext context, UIComponent component) { |
53 | 3 | AssertionUtil.assertNotNull("context is null.", context); |
54 | 2 | AssertionUtil.assertNotNull("component is null.", component); |
55 | 1 | if (!(component instanceof EditableValueHolder)) { |
56 | 1 | throw new NoEditableValueHolderRuntimeException(component |
57 | |
.getClass()); |
58 | |
} |
59 | 0 | EditableValueHolder evh = (EditableValueHolder) component; |
60 | 0 | Map paramValuesMap = context.getExternalContext() |
61 | |
.getRequestParameterValuesMap(); |
62 | 0 | String clientId = component.getClientId(context); |
63 | 0 | String[] value = null; |
64 | 0 | if (paramValuesMap.containsKey(clientId)) { |
65 | 0 | value = (String[]) paramValuesMap.get(clientId); |
66 | |
} |
67 | 0 | if (value != null) { |
68 | 0 | evh.setSubmittedValue(value); |
69 | |
} else { |
70 | 0 | evh.setSubmittedValue(new String[0]); |
71 | |
} |
72 | 0 | } |
73 | |
|
74 | |
} |