Vaadin 8 Grid Inline Edit with DateTimeField and SQL Timestamp

Hi
I am trying to implement this in my Grid:[code]
DateTimeField dateField = new DateTimeField();

Column<Sector, Timestamp> columnTimeStamp = addColumn(sector->sector.getDeparturetimetarget());

columnTimeStamp.setRenderer(time ->{
Instant instant = Instant.ofEpochMilli(time.getTime());
LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneOffset.UTC);
return ldt;
},new LocalDateTimeRenderer());

columnTimeStamp.setId(COLUMN_NAME.DEPARTURE.getValue());

columnTimeStamp.setEditorComponent(dateField);
[/code]The grid displays the data correctly, but when I double click for editing its show this error:

java.lang.ClassCastException: java.sql.Timestamp cannot be cast to java.time.temporal.Temporal at com.vaadin.ui.AbstractDateField.doSetValue(AbstractDateField.java:73)[140:com.vaadin.server:8.1.1]

at com.vaadin.ui.AbstractField.setValue(AbstractField.java:140)[140:com.vaadin.server:8.1.1]

at com.vaadin.ui.AbstractField.setValue(AbstractField.java:53)[140:com.vaadin.server:8.1.1]

at com.vaadin.data.Binder$BindingImpl.initFieldValue(Binder.java:893)
at com.vaadin.data.Binder$BindingImpl.access$100(Binder.java:766)
at com.vaadin.data.Binder.lambda$readBean$2(Binder.java:1386)
at java.lang.Iterable.forEach(Iterable.java:75)[:1.8.0_112]

at com.vaadin.data.Binder.readBean(Binder.java:1386)
at com.vaadin.ui.components.grid.EditorImpl.doEdit(EditorImpl.java:224)
at com.vaadin.ui.components.grid.EditorImpl$1.bind(EditorImpl.java:150)

What do I miss ?

Well, as the Stack Trace so kindly says, somewhere in your code you are trying to implicitly cast an object of type java.sql.Timestamp to java.time.temporal.Temporal. I would assume that this happens either in line 6 or 7 of the code you posted. A ClassCastException means that the types you are trying to convert from and to are incompatible for this operation. Casting is always only possible from a subclass to a superclass or superinterface, but never from a superclass or -interface to a subclass or -interface. It is neither possible to cast to a completely unrelated (in hierarchy tree) class/interface.


https://docs.oracle.com/javase/8/docs/api/java/lang/ClassCastException.html

I have now a working solution, but i dont know if its the best way :

Column<Sector, Timestamp> columnTimeStamp = addColumn(
new ValueProvider<Sector, Timestamp>() { @Override public Timestamp apply(Sector sector) { return sector.getDeparturetimetarget(); } },
new ValueProvider<Timestamp, String>() { @Override public String apply(Timestamp timestamp) { String time = timestamp.toLocalDateTime().format(formatter).toString(); return time; } }
);

columnTimeStamp.setId(COLUMN_NAME.DEPARTURE.getValue());

columnTimeStamp.setEditorBinding(
getEditor().getBinder().forField(dateField)
.withConverter(new LocalDateTimeToSqlTimestampConverter())
.bind(Sector::getDeparturetimetarget,Sector::setDeparturetimetarget));
columnTimeStamp.setEditable(true);

Is there a nicer solution?

Yes, the first argument in addColumn can be simplified to Sector::getDeparturetimetarget.