How to format a DateField in an editable Table?

I’m trying to figure out how to format a DateField in an editable table to display the date as ‘yyyy-MM-dd’.

In a non-editable table, I can subclass Table and override formatPropertyValue with the necessary code, such as:


	protected String formatPropertyValue(Object rowId, Object colId, Property property) {

		logger.debug("formatPropertyValue");
		
        Object v = property.getValue();
        if (v instanceof Date) {
            return new SimpleDateFormat("yyyy-MM-dd").format(v);
        }
        else
        	return super.formatPropertyValue(rowId, colId, property);
	}

But when the table is marked as editable, it no longer calls formatPropertyValue. Instead, I’ve noticed it calls fieldFactory.createField. So I’ve tried to set the TableFieldFactory as follows:


	dataTable.setTableFieldFactory(new DefaultFieldFactory() {
	            @Override
				public Field createField(Container container, Object itemId, Object propertyId, com.vaadin.ui.Component uiContext) {
	                // Create fields by their class
	                Class<?> cls = container.getType(propertyId);

	                // Create a DateField with year resolution for dates
	                if (Date.class.isAssignableFrom(cls)) {
	                    DateField df = new DateField();
	                    df.setResolution(DateField.RESOLUTION_DAY);
	                    df.setPropertyDataSource(new PropertyFormatter() {
							
							@Override
							public Object parse(String formattedValue) throws Exception {
								return DateUtils.parseDate(formattedValue, "yyyy-MM-dd");
							}
							
							@Override
							public String format(Object value) {
								if( Date.class.isAssignableFrom(value.getClass()))
									return new SimpleDateFormat( "yyyy-MM-dd").format((Date)value);
								else
									return "????";
							}
						});
	                    
	                    return df;
	                }

	                // Otherwise use the default field factory 
	                return super.createField(container, itemId, propertyId, uiContext);
	            }
	        });

However, when I do that, I get the following error:


 [java.lang.IllegalArgumentException: DateField only supports Date properties]
 with root cause
java.lang.IllegalArgumentException: DateField only supports Date properties
	at com.vaadin.ui.DateField.setPropertyDataSource(DateField.java:590)
	at com.ia.vaadin.TabbedWindow$1.createField(TabbedWindow.java:128)
	at com.vaadin.ui.Table.getPropertyValue(Table.java:3417)
	at com.vaadin.ui.Table.getVisibleCellsNoCache(Table.java:1853)
...

So I’m a little confused. If I also subclass getType() to return Date.class, then I have to modify getValue() to return a Date object. But I don’t know how where to get value to return. Additionally, according to the API, getValue() is supposed to return the formatted value, which a Date object is not.

So either I am barking up the wrong tree, or I am a little lost as to how to properly create my PropertyFormatter. The Book of Vaadin pretty much says it is too complicated to explain so it is left up to the reader to figure out on his own.

Can anyone help please?

Thanks!

Eric