| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.convert; |
| 17 | |
|
| 18 | |
import javax.faces.component.StateHolder; |
| 19 | |
import javax.faces.component.UIComponent; |
| 20 | |
import javax.faces.context.FacesContext; |
| 21 | |
import javax.faces.convert.Converter; |
| 22 | |
import javax.faces.convert.ConverterException; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | 41 | public class NullConverter implements Converter, StateHolder { |
| 29 | |
|
| 30 | 1 | private static final String[] DEFAULT_NULL_VALUES = new String[] { "", "on" }; |
| 31 | |
|
| 32 | 41 | private String[] nullValues = DEFAULT_NULL_VALUES; |
| 33 | |
|
| 34 | |
private boolean transientValue; |
| 35 | |
|
| 36 | |
public String[] getNullValues() { |
| 37 | 0 | return nullValues; |
| 38 | |
} |
| 39 | |
|
| 40 | |
public void setNullValues(String[] nullValues) { |
| 41 | 0 | this.nullValues = nullValues; |
| 42 | 0 | } |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
public Object getAsObject(FacesContext context, UIComponent component, |
| 48 | |
String value) throws ConverterException { |
| 49 | |
|
| 50 | 3 | for (int i = 0; i < nullValues.length; ++i) { |
| 51 | 2 | if (nullValues[i].equalsIgnoreCase(value)) { |
| 52 | 0 | return null; |
| 53 | |
} |
| 54 | |
} |
| 55 | 1 | return value; |
| 56 | |
} |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
public String getAsString(FacesContext context, UIComponent component, |
| 62 | |
Object value) throws ConverterException { |
| 63 | |
|
| 64 | 0 | if (value == null) { |
| 65 | 0 | return ""; |
| 66 | |
} |
| 67 | 0 | return value.toString(); |
| 68 | |
} |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
public Object saveState(FacesContext context) { |
| 74 | 0 | Object[] values = new Object[1]; |
| 75 | 0 | values[0] = nullValues; |
| 76 | 0 | return values; |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
public void restoreState(FacesContext context, Object state) { |
| 83 | 0 | Object[] values = (Object[]) state; |
| 84 | 0 | nullValues = (String[]) values[0]; |
| 85 | |
|
| 86 | 0 | } |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
public boolean isTransient() { |
| 92 | 0 | return transientValue; |
| 93 | |
} |
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
public void setTransient(boolean transientValue) { |
| 99 | 0 | this.transientValue = transientValue; |
| 100 | 0 | } |
| 101 | |
|
| 102 | |
} |