1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.sampleu.demo.kitchensink;
17
18 import org.apache.commons.lang.StringUtils;
19 import java.beans.PropertyEditorSupport;
20 import java.io.Serializable;
21
22
23
24
25 public class UITestPropertyEditor extends PropertyEditorSupport implements Serializable {
26 private static final long serialVersionUID = -4113846709722954737L;
27
28
29
30
31 @Override
32 public String getAsText() {
33 Object obj = this.getValue();
34
35 if (obj == null) {
36 return null;
37 }
38
39 String displayValue = obj.toString();
40 if (displayValue.length() > 3) {
41 displayValue = StringUtils.substring(displayValue, 0, 3) + "-" + StringUtils.substring(displayValue, 3);
42 }
43
44 return displayValue;
45 }
46
47
48
49
50 @Override
51 public void setAsText(String text) {
52 String value = text;
53 if (StringUtils.contains(value, "-")) {
54 value = StringUtils.replaceOnce(value, "-", "");
55 }
56
57 this.setValue(value);
58 }
59
60 }