| 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.component.ValueHolder; |
| 23 | |
import javax.faces.context.FacesContext; |
| 24 | |
|
| 25 | |
import org.seasar.framework.util.AssertionUtil; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | 412 | public abstract class AbstractDecoder implements Decoder { |
| 31 | |
|
| 32 | |
public void decode(FacesContext context, UIComponent component) { |
| 33 | 20 | AssertionUtil.assertNotNull("context is null.", context); |
| 34 | 19 | AssertionUtil.assertNotNull("component is null.", component); |
| 35 | 18 | ValueHolderWrapper wrapper = createValueHolderWrapper(component); |
| 36 | 17 | Map paramMap = getRequestParameterMap(context); |
| 37 | 17 | String clientId = getClientId(component, context); |
| 38 | 17 | if (paramMap.containsKey(clientId)) { |
| 39 | 9 | Object value = paramMap.get(clientId); |
| 40 | 9 | wrapper.setValue(value); |
| 41 | |
} |
| 42 | 17 | } |
| 43 | |
|
| 44 | |
public void decodeMany(FacesContext context, UIComponent component) { |
| 45 | 9 | AssertionUtil.assertNotNull("context is null.", context); |
| 46 | 8 | AssertionUtil.assertNotNull("component is null.", component); |
| 47 | 7 | ValueHolderWrapper wrapper = createValueHolderWrapper(component); |
| 48 | 6 | Map paramValuesMap = getRequestParameterValuesMap(context); |
| 49 | 6 | String clientId = getClientId(component, context); |
| 50 | 6 | String[] value = null; |
| 51 | 6 | if (paramValuesMap.containsKey(clientId)) { |
| 52 | 3 | value = (String[]) paramValuesMap.get(clientId); |
| 53 | |
} |
| 54 | 6 | if (value != null) { |
| 55 | 3 | wrapper.setValue(value); |
| 56 | |
} else { |
| 57 | 3 | wrapper.setValue(new String[0]); |
| 58 | |
} |
| 59 | 6 | } |
| 60 | |
|
| 61 | |
protected abstract ValueHolderWrapper createValueHolderWrapper( |
| 62 | |
UIComponent component); |
| 63 | |
|
| 64 | |
protected Map getRequestParameterMap(FacesContext context) { |
| 65 | 17 | return context.getExternalContext().getRequestParameterMap(); |
| 66 | |
} |
| 67 | |
|
| 68 | |
protected Map getRequestParameterValuesMap(FacesContext context) { |
| 69 | 6 | return context.getExternalContext().getRequestParameterValuesMap(); |
| 70 | |
} |
| 71 | |
|
| 72 | |
protected String getClientId(UIComponent component, FacesContext context) { |
| 73 | 23 | return component.getClientId(context); |
| 74 | |
} |
| 75 | |
|
| 76 | 412 | protected static class ValueHolderWrapper { |
| 77 | |
|
| 78 | |
private ValueHolder holder; |
| 79 | |
|
| 80 | 23 | public ValueHolderWrapper(ValueHolder holder) { |
| 81 | 23 | this.holder = holder; |
| 82 | 23 | } |
| 83 | |
|
| 84 | |
public void setValue(Object value) { |
| 85 | 15 | if (holder instanceof EditableValueHolder) { |
| 86 | 15 | ((EditableValueHolder) holder).setSubmittedValue(value); |
| 87 | |
} else { |
| 88 | 0 | holder.setValue(value); |
| 89 | |
} |
| 90 | 15 | } |
| 91 | |
|
| 92 | |
public Object getValue() { |
| 93 | 0 | if (holder instanceof EditableValueHolder) { |
| 94 | 0 | return ((EditableValueHolder) holder).getSubmittedValue(); |
| 95 | |
} else { |
| 96 | 0 | return holder.getValue(); |
| 97 | |
} |
| 98 | |
} |
| 99 | |
} |
| 100 | |
|
| 101 | |
} |