Migrating to vaadin 24 LocalDateRenderer

Hello,

we are in the progress of migrating from vaadin 23 to 24 and have converted/adapted most parts already.
But one this we struggle with is the removal of the the LocalDateRenderer constructors from here:
https://github.com/vaadin/flow/issues/15665
com.vaadin.flow.data.renderer.LocalDateRenderer​(ValueProvider<SOURCE, LocalDate>, DateTimeFormatter)
com.vaadin.flow.data.renderer.LocalDateTimeRenderer​(ValueProvider<SOURCE, LocalDateTime>, DateTimeFormatter)

In our code we had this
case AdminField.DATE, AdminField.DATE_RO → {
col = grid.addColumn(new LocalDateRenderer<>(
item → item.getLocalDate(fieldConfig.getField()),
UIHelper.getDateFormat()));
and now the java 17 compiler tells me
cannot infer type arguments for com.vaadin.flow.data.renderer.LocalDateRenderer<>

The UIHelper.getDateFormat() returns a java.time.format.DateTimeFormatter whith the desired format+locale

This https://stackoverflow.com/questions/77699865/vaadin-cannot-infer-type-arguments-for-localdaterenderer does not apply, since the item.getLocalDate() already returns a LocalDate class value

Change your second argument to () → yourCode

Unfortunally this does not work

            col = grid.addColumn(new LocalDateRenderer<>(
                    item -> item.getLocalDate(fieldConfig.getField()),
                    () -> UIHelper.getDateFormat()));

Gives then incompatible types: java.lang.String cannot be converted to java.util.Date

Wait… Date?

https://github.com/vaadin/flow-components/blob/9358d2c5a8e6a1090e2177c0b1c7c4f9ec73e6ff/vaadin-renderer-flow-parent/vaadin-renderer-flow/src/main/java/com/vaadin/flow/data/renderer/LocalDateRenderer.java#L158

This is the constructor - it has no Date Signature

I’m using the LocalDate constructor, similar to the NumberRenderer

It should pick up this one:
public LocalDateRenderer(ValueProvider<SOURCE, LocalDate> valueProvider,
SerializableSupplier formatter)

Is the SerializableSupplier the problem?

That’s why I suggested to change your second argument to () → yourCode to make it a supplier; after that you confused me with the error message which mentioned a java util Date… which isn’t really a thing here

col = grid.addColumn(new LocalDateRenderer<>(
item → item.getLocalDate(fieldConfig.getField()),
() → DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)));

Gives incompatible types: java.lang.String cannot be converted to java.util.Date

Ok, this works

col = grid.addColumn(new LocalDateRenderer<>(
item → LocalDate.now(),
() → DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)));

Then there is some type problem in my getLocalDate() interface.
I think I should be able to trak this one

Sometimes it helps if you let your IDE create an anonymous inner class to replace the lambda; that makes the types involved explicit

It’s solved now, the problem was comming from the Grid which was referencing in another context where the getLocalDate() was implemented differently… :frowning_with_open_mouth:

Thanks for your help