View Javadoc

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