01: package org.jreform.internal;
02:
03: import static org.jreform.CheckableState.CHECKED;
04: import static org.jreform.CheckableState.UNCHECKED;
05:
06: import javax.servlet.http.HttpServletRequest;
07:
08: import org.jreform.CheckableState;
09: import org.jreform.Checkbox;
10: import org.jreform.Criterion;
11: import org.jreform.InputDataType;
12:
13: class CheckboxImpl<T> extends InputImpl<T> implements Checkbox<T> {
14: CheckboxImpl(InputDataType<T> type, String name,
15: Criterion<T>... criteria) {
16: super (type, name, criteria);
17:
18: setRequired(false); // single checkbox always optional
19: }
20:
21: /**
22: * A checkbox is always valid (and optional) since its value is
23: * <code>null</code> when it's submitted unchecked.
24: */
25: final boolean validate(HttpServletRequest req) {
26: return super .validate(req);
27: }
28:
29: public CheckableState getState() {
30: return "".equals(getValueAttribute()) ? UNCHECKED : CHECKED;
31: }
32:
33: }
|