01: package simpleorm.simplewebapp.scalarFields;
02:
03: import simpleorm.simplewebapp.core.WField;
04:
05: public class WFieldBoolean extends WField {
06: public WFieldBoolean(String name) {
07: this (name, WField.CHECKBOX);
08: }
09:
10: public WFieldBoolean(String name, String widget) {
11: super (name, widget);
12: getOptions().add("True");
13: getOptions().add("False");
14: }
15:
16: /** This is used to actually set the check box to being checked. */
17: public boolean getBooleanValue(boolean defalt) {
18: return value != null ? (Boolean) value : defalt;
19: }
20:
21: protected String format() {
22: return value == null ? null : value.toString();
23: }
24:
25: protected void parse(String rawText) {
26: if (rawText == null)
27: value = false; // if checkbox not checked
28: else if ("on".equals(rawText))
29: value = true; // returned from checkbox
30: else
31: value = Boolean.valueOf(rawText);
32: }
33:
34: public Class getValueClass() {
35: return Boolean.class;
36: }
37:
38: public Boolean getValue() {
39: // null just retrns null, not false.
40: return (Boolean) super.getValue();
41: }
42:
43: }
|