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.api.util.RiceKeyConstants;
19 import org.kuali.rice.core.web.format.FormatException;
20
21 import java.io.Serializable;
22 import java.sql.Date;
23 import java.text.ParseException;
24 import java.util.Calendar;
25
26
27
28
29
30
31
32 public class UifCalendarEditor extends UifDateEditor implements Serializable {
33 private static final long serialVersionUID = 8123569337264797008L;
34
35
36
37
38
39
40 @Override
41 public String getAsText() {
42 if (this.getValue() == null) {
43 return null;
44 }
45
46 if ("".equals(this.getValue())) {
47 return null;
48 }
49
50 return getDateTimeService().toDateString(new Date(((java.util.Calendar) this.getValue()).getTimeInMillis()));
51 }
52
53
54
55
56
57
58
59
60
61 protected Object convertToObject(String text) throws IllegalArgumentException {
62 try {
63
64 if (text == null || text.equals("")) {
65 return null;
66 }
67
68 Date result = getDateTimeService().convertToSqlDate(text);
69 Calendar calendar = getDateTimeService().getCalendar(result);
70 calendar.setTime(result);
71
72 if (calendar.get(Calendar.YEAR) < 1000 && verbatimYear(text).length() < 4) {
73 throw new FormatException("illegal year format", RiceKeyConstants.ERROR_DATE, text);
74 }
75
76 return calendar;
77 } catch (ParseException e) {
78 throw new FormatException("parsing", RiceKeyConstants.ERROR_DATE, text, e);
79 }
80 }
81
82 }