1 /*
2 * Copyright 2011 The Kuali Foundation Licensed under the Educational Community
3 * License, Version 1.0 (the "License"); you may not use this file except in
4 * compliance with the License. You may obtain a copy of the License at
5 * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law
6 * or agreed to in writing, software distributed under the License is
7 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 * KIND, either express or implied. See the License for the specific language
9 * governing permissions and limitations under the License.
10 */
11 package org.kuali.rice.krad.web.bind;
12
13 import java.sql.Date;
14 import java.sql.Timestamp;
15
16 /**
17 * This PropertyEditor converts between date display strings and
18 * <code>java.sql.Timestamp</code> objects using the
19 * <code>org.kuali.rice.core.api.datetime.DateTimeService</code>
20 *
21 * @author Kuali Rice Team (rice.collab@kuali.org)
22 */
23 public class UifTimestampEditor extends UifDateEditor {
24
25 /**
26 * This overridden method uses the
27 * <code>org.kuali.rice.core.api.datetime.DateTimeService</code> to convert
28 * the time stamp object to the display string.
29 *
30 * @see UifDateEditor#getAsText()
31 */
32 @Override
33 public String getAsText() {
34 if (this.getValue() == null) {
35 return null;
36 }
37 if ("".equals(this.getValue())) {
38 return null;
39 }
40
41 return getDateTimeService().toDateTimeString((Timestamp) this.getValue());
42 }
43
44 /**
45 * This overridden method converts the display string to a
46 * <code>java.sql.Timestamp</code> object using the
47 * <code>org.kuali.rice.core.api.datetime.DateTimeService</code>.
48 *
49 * @see UifDateEditor#setAsText(java.lang.String)
50 */
51 @Override
52 public void setAsText(String text) throws IllegalArgumentException {
53 this.setValue(new Timestamp(((Date) super.convertToObject(text)).getTime()));
54 }
55
56 }