Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Show Calendar Attribute in Table
Hi everybody,
i´m using a table to show some items.
this item contains an attribute of the type "java.util.Calendar". when i try to show this item attribute in the table, it looks like this: java.util.GregorianCalendar[time=1420736297330,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Berlin",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=143,lastRule=java.util.SimpleTimeZone[id=Europe/Berlin,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2015,MONTH=0,WEEK_OF_YEAR=2,WEEK_OF_MONTH=2,DAY_OF_MONTH=8,DAY_OF_YEAR=8,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=58,SECOND=17,MILLISECOND=330,ZONE_OFFSET=3600000,DST_OFFSET=0]
Is there a way to show a correct date and time string?! like 2015-07-10 11:44:14
Here´s some code:
public class MyItem{
private Calendar date;
public Calendar getDate() {
return date;
}
....
}
public class MyView extends View{
private Table table;
private BeanItemContainer<MyItem> myContainer;
private Table buildTable() {
table = new Table();
myContainer= new BeanItemContainer<MyItem>(MyItem.class);
table.setContainerDataSource(myContainer);
....
}
A couple of ways; the easiest would probably be to extend your table and override the FormatPropertyValue mathod. In the method, you can check if the property is of type Calendar, and return the representation that you want. Another way is to add a GeneratedColumn with the same property id as the field in your container (in this case it would be 'date'). The generated column will effectively override the one from the container, but will require you to use a Component in the cell, slowing the table down.