grid - how to format a given date string

Hi,

I do have problems with formatting a String which shall represent date and time.
Using latest eclipse and vaadin 14.

String contains e.g. 201911051300

When trying this, derived from the grid example here: https://vaadin.com/docs/v14/flow/components/tutorial-flow-grid.html#local-date-time-renderer

myGrid.addColumn(new LocalDateRenderer<>(Item::getTime,DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)));

eclipse marks it red and shows following error:

Cannot infer type arguments for LocalDateRenderer<>

Any idea why it is that way? Thanks for any hints on this!

Manfred

Hi again,

well, I haven’t made any real progress on this while I’m trying to solve it…

As far as I can tell:
I have a String and fill a formatter with that pattern:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmm");`

From the flow grid tutorial I try to use this expression:

grid.addColumn(new LocalDateTimeRenderer<>(
        Item::getPurchaseDate,
        "dd/MM HH:mm:ss")
).setHeader("Purchase date and time");

AFAIK Item::getPurchaseDate has to be already a LocalDateTime object, but my item::getTime gives just a String, I tried to use the standard mechanisms to convert that String to LocalDateTime:
LocalDateTime.parse(Item::getTime, formatter)
where .parse is complaining The method parse(CharSequence, DateTimeFormatter) in the type LocalDateTime is not applicable for the arguments (item::getTime, DateTimeFormatter). So I have tried Casting item::getTime to CharSequence:

grid.addColumn(new LocalDateTimeRenderer<>(
        LocalDateTime.parse((CharSequence) Item::getTime, formatter),
        "dd/MM HH:mm:ss")
).setHeader("Purchase date and time");

which leaves me with same error message as above:

Cannot infer type arguments for LocalDateTimeRenderer<>

What am I doing wrong here? Any hint appreciated.

Manfred

In the case that you want to do a casting you must take into account a little how to access the properties of the object in the case of Item::getDate the properties of the objects of the entities cannot be observed, for this use Item → table. addColumn(new LocalDateRenderer<>(Item
→ item.getDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), “dd-MM-yyyy”)).setHeader(“DATE ​​OF ANYTHING”);

I had this same problem when I was migrating an application from Vaadin 7 to Vaadin 24

sorry i use a traslate to write this post