01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.components.table.renderer;
06:
07: import com.opensymphony.webwork.components.table.WebTable;
08:
09: import java.text.SimpleDateFormat;
10:
11: /**
12: * @author $author$
13: * @version $Revision: 1282 $
14: */
15: public class DateCellRenderer extends AbstractCellRenderer {
16:
17: SimpleDateFormat _formater = new SimpleDateFormat();
18:
19: /**
20: * this is the string that SimpleDateFormat needs to display the date
21: *
22: * @see SimpleDateFormat
23: */
24: String _formatString = null;
25:
26: public DateCellRenderer() {
27: super ();
28: }
29:
30: public String getCellValue(WebTable table, Object data, int row,
31: int col) {
32: java.util.Date cellValue = null;
33:
34: if (data == null) {
35: return "";
36: }
37:
38: if (data instanceof java.util.Date) {
39: return _formater.format((java.util.Date) data);
40: }
41:
42: return data.toString();
43: }
44:
45: public void setFormatString(String format) {
46: _formatString = format;
47: _formater.applyPattern(_formatString);
48: }
49: }
|