1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.render; |
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 | 8 | public class DefaultDecoder implements Decoder { |
31 | |
|
32 | |
public void decode(FacesContext context, UIComponent component) { |
33 | 5 | AssertionUtil.assertNotNull("context is null.", context); |
34 | 4 | AssertionUtil.assertNotNull("component is null.", component); |
35 | 3 | EditableValueHolder evh = getEditableHolder(component); |
36 | 2 | Map paramMap = getRequestParameterMap(context); |
37 | 2 | String clientId = getClientId(component, context); |
38 | 2 | if (paramMap.containsKey(clientId)) { |
39 | 1 | Object submittedValue = paramMap.get(clientId); |
40 | 1 | evh.setSubmittedValue(submittedValue); |
41 | |
} |
42 | 2 | } |
43 | |
|
44 | |
public void decodeMany(FacesContext context, UIComponent component) { |
45 | 3 | AssertionUtil.assertNotNull("context is null.", context); |
46 | 2 | AssertionUtil.assertNotNull("component is null.", component); |
47 | 1 | EditableValueHolder evh = getEditableHolder(component); |
48 | 0 | Map paramValuesMap = getRequestParameterValuesMap(context); |
49 | 0 | String clientId = getClientId(component, context); |
50 | 0 | String[] value = null; |
51 | 0 | if (paramValuesMap.containsKey(clientId)) { |
52 | 0 | value = (String[]) paramValuesMap.get(clientId); |
53 | |
} |
54 | 0 | if (value != null) { |
55 | 0 | evh.setSubmittedValue(value); |
56 | |
} else { |
57 | 0 | evh.setSubmittedValue(new String[0]); |
58 | |
} |
59 | 0 | } |
60 | |
|
61 | |
protected Map getRequestParameterMap(FacesContext context) { |
62 | 2 | return context.getExternalContext().getRequestParameterMap(); |
63 | |
} |
64 | |
|
65 | |
protected Map getRequestParameterValuesMap(FacesContext context) { |
66 | 0 | return context.getExternalContext().getRequestParameterValuesMap(); |
67 | |
} |
68 | |
|
69 | |
protected String getClientId(UIComponent component, FacesContext context) { |
70 | 2 | return component.getClientId(context); |
71 | |
} |
72 | |
|
73 | |
protected EditableValueHolder getEditableHolder(UIComponent component) { |
74 | 4 | AssertionUtil.assertNotNull("component is null.", component); |
75 | 4 | if (!(component instanceof EditableValueHolder)) { |
76 | 2 | throw new NoEditableValueHolderRuntimeException(component |
77 | |
.getClass()); |
78 | |
} |
79 | 2 | return (EditableValueHolder) component; |
80 | |
|
81 | |
} |
82 | |
} |