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 org.kuali.rice.core.web.format.FormatException;
19 import org.kuali.rice.core.web.format.Formatter;
20
21 import java.beans.PropertyEditorSupport;
22
23
24
25
26
27
28
29 public class UifKnsFormatterPropertyEditor extends PropertyEditorSupport {
30 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(UifKnsFormatterPropertyEditor.class);
31
32 Formatter formatter;
33
34
35
36
37
38
39 public UifKnsFormatterPropertyEditor(Class<? extends Formatter> formatterClass) {
40 super();
41 try {
42 formatter = formatterClass.newInstance();
43 }
44 catch (InstantiationException e) {
45 throw new FormatException("Couldn't create an instance of class " + formatterClass, e);
46 }
47 catch (IllegalAccessException e) {
48 throw new FormatException("Couldn't create an instance of class " + formatterClass, e);
49 }
50
51
52
53 formatter.setPropertyType(formatterClass);
54 }
55
56 @Override
57 public String getAsText() {
58 try {
59 return (String) formatter.formatForPresentation(getValue());
60 } catch (FormatException e) {
61 LOG.error("FormatException: " + e.getLocalizedMessage(), e);
62 throw e;
63 }
64 }
65
66 @Override
67 public void setAsText(String text) throws IllegalArgumentException {
68 try {
69 this.setValue(formatter.convertFromPresentationFormat(text));
70 } catch (FormatException e) {
71 LOG.error("FormatException: " + e.getLocalizedMessage(), e);
72 throw e;
73 }
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 }
96
97
98 }