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
20
21
22
23
24
25
26 public class UifBooleanEditor extends PropertyEditorSupport {
27
28 private static final String TRUE_VALUES = "/true/yes/y/on/1/";
29 private static final String FALSE_VALUES = "/false/no/n/off/0/";
30
31 private static final String TRUE_VALUE = "true";
32 private static final String FALSE_VALUE = "false";
33
34 @Override
35 public String getAsText() {
36 if(this.getValue() == null) {
37 return "";
38 }
39 else if(((Boolean)this.getValue()).booleanValue()) {
40 return TRUE_VALUE;
41 }
42 else {
43 return FALSE_VALUE;
44 }
45 }
46
47 @Override
48 public void setAsText(String text) throws IllegalArgumentException {
49 String input = null;
50
51 if(text != null) {
52 StringBuilder builder = new StringBuilder();
53 builder.append("/").append(text.toLowerCase()).append("/");
54 input = builder.toString();
55
56 if(TRUE_VALUES.contains(input)) {
57 this.setValue(Boolean.TRUE);
58 }
59 else if(FALSE_VALUES.contains(input)) {
60 this.setValue(Boolean.FALSE);
61 }
62 else {
63 input = null;
64 }
65 }
66
67 if(input == null) {
68 throw new IllegalArgumentException("Invalid boolean input: " + text);
69 }
70 }
71
72 }