View Javadoc

1   /**
2    * Copyright 2005-2011 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.sql.Date;
19  import java.sql.Timestamp;
20  
21  /**
22   * This PropertyEditor converts between date display strings and
23   * <code>java.sql.Timestamp</code> objects using the
24   * <code>org.kuali.rice.core.api.datetime.DateTimeService</code>
25   * 
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class UifTimestampEditor extends UifDateEditor {
29  
30      /**
31       * This overridden method uses the
32       * <code>org.kuali.rice.core.api.datetime.DateTimeService</code> to convert
33       * the time stamp object to the display string.
34       * 
35       * @see UifDateEditor#getAsText()
36       */
37      @Override
38      public String getAsText() {
39          if (this.getValue() == null) {
40              return null;
41          }
42          if ("".equals(this.getValue())) {
43              return null;
44          }
45  
46          return getDateTimeService().toDateTimeString((Timestamp) this.getValue());
47      }
48  
49      /**
50       * This overridden method converts the display string to a
51       * <code>java.sql.Timestamp</code> object using the
52       * <code>org.kuali.rice.core.api.datetime.DateTimeService</code>.
53       * 
54       * @see UifDateEditor#setAsText(java.lang.String)
55       */
56      @Override
57      public void setAsText(String text) throws IllegalArgumentException {
58          this.setValue(new Timestamp(((Date) super.convertToObject(text)).getTime()));
59      }
60  
61  }