FernandoPaiva
FernandoPaiva

Reputation: 4460

Formatting vaadin table values?

Problem is solved. Using JPAContainer not need use addContainerProperty(). I comment the line and bingo, now works with values formated.

Now works !

final Table table = new Table("Formatted Table") {
    @Override
    protected String formatPropertyValue(Object rowId,
            Object colId, Property property) {
        // Format by property type
        if (property.getType() == Date.class) {
            SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            return df.format((Date)property.getValue());
        }

        return super.formatPropertyValue(rowId, colId, property);
    }
};

// not need with jpacontainer
//table.addContainerProperty("Time", Date.class, null);

Upvotes: 1

Views: 3214

Answers (1)

nexus
nexus

Reputation: 2937

In Vaadin 7 you can add a Converter to your component. There's no need to override / extend the Table class.

table.setConverter(PROPERTY, new StringToDateConverter());

You can even change the DateFormat by simply overriding StringToDateConverters public DateFormat getFormat(Locale locale) method.

More information here and here.

Upvotes: 4

Related Questions