1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.web.bind;
17
18 import java.beans.PropertyEditorSupport;
19 import java.io.Serializable;
20
21
22
23
24
25
26 public class UifBooleanEditor extends PropertyEditorSupport implements Serializable {
27 private static final long serialVersionUID = -6333792216543862346L;
28
29 private static final String TRUE_VALUES = "/true/yes/y/on/1/";
30 private static final String FALSE_VALUES = "/false/no/n/off/0/";
31
32 private static final String TRUE_VALUE = "true";
33 private static final String FALSE_VALUE = "false";
34
35
36
37
38
39
40
41
42
43
44
45
46 @Override
47 public String getAsText() {
48 if(this.getValue() == null) {
49 return "";
50 }
51 else if(((Boolean)this.getValue()).booleanValue()) {
52 return TRUE_VALUE;
53 }
54 else {
55 return FALSE_VALUE;
56 }
57 }
58
59
60
61
62
63
64
65
66
67
68
69
70 @Override
71 public void setAsText(String text) throws IllegalArgumentException {
72 String input = null;
73
74 if(text != null) {
75 StringBuilder builder = new StringBuilder();
76 builder.append("/").append(text.toLowerCase()).append("/");
77 input = builder.toString();
78
79 if(TRUE_VALUES.contains(input)) {
80 this.setValue(Boolean.TRUE);
81 }
82 else if(FALSE_VALUES.contains(input)) {
83 this.setValue(Boolean.FALSE);
84 }
85 else {
86 input = null;
87 }
88 }
89
90 if(input == null) {
91 throw new IllegalArgumentException("Invalid boolean input: " + text);
92 }
93 }
94
95 }