Timestamp类的Vaadin表列格式

时间:2015-01-20 21:40:11

标签: vaadin

我正在使用带有sql容器的表。容器的数据源是自由格式查询。其中一个字段是发票日期,在sql server中,该字段是一个较小的日期时间。我已经覆盖了formatPropertyValue函数,当我调试它时,“property.getType()”返回“Timestamp”。所以这就是我在函数中所做的。

if (property.getType() == Timestamp.class) {
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        if (property.getValue() == null) {
            return null;
        } else {
            System.out.println(df.format( (Date) property.getValue()));
            return df.format( (Date) property.getValue());

        }
    }

当我运行应用程序时,我收到“com.vaadin.ui.table $ cacheupdateexception”错误。

我通过更改sql语句,如“query =”SELECT convert(varchar(10),INVOICE_DATE,110)作为INVOICE_DATE,......“但我想知道是否有一种正确的格式化Timestamp字段的方法

谢谢,

托马斯金。

1 个答案:

答案 0 :(得分:0)

我发现我的代码有错误。它应该是

return df.format( (Timestamp) property.getValue());

而不是

return df.format( (Date) property.getValue());

它现在正在工作。