Alejandro Gay
Alejandro Gay

Reputation: 21

Vaadin Cannot infer type arguments for LocalDateRenderer<>

I have a grid in Vaadin 22 and I'm trying to format a date column in my grid and in the eclipse editor the line has an error indicating 'Cannot infer type arguments for LocalDateRenderer<>'

line with the error

grid.addColumn(new LocalDateRenderer<>(Event::getEventdate, "dd/mm/yyyy"))).setHeader("Event Date");

My entity in Vaadin is defined as follow

package com.giftslists.application.data.entity;


import java.util.Date;

import javax.persistence.Entity;

import com.giftslists.application.data.AbstractEntity;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

@Entity
public class Event  extends AbstractEntity 
{
    
    @NotNull
    @NotBlank
    private String description;
    
    @NotNull
    private Date eventdate;
    
    @NotNull
    @NotBlank
    private String createdby;
    
    @NotNull
    private Date createdate;
    
    

    public Event(String description, Date eventdate, String createdby) {
        super();
        this.description = description;
        this.eventdate = eventdate;
        this.createdby = createdby;
        this.createdate = new Date();
    }

    public Event() {
    }

    public void updateEvent(String description, Date eventdate, String createdby, Date createdate) {
        this.description = description;
        this.eventdate = eventdate;
        this.createdby = createdby;
        this.createdate = createdate;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getEventdate() {
        return eventdate;
    }

    public void setEventdate(Date eventdate) {
        this.eventdate = eventdate;
    }

    public String getCreatedby() {
        return createdby;
    }

    public void setCreatedby(String createdby) {
        this.createdby = createdby;
    }

    public Date getCreatedate() {
        return createdate;
    }

    public void setCreatedate(Date createdate) {
        this.createdate = createdate;
    }

    
  
}

I've tried to cast to Event and String and that make it worse like **LocalDateRenderer<>((Event) Event::getEventdate, "dd/mm/yyyy") ** I've tried as well LocalDateRenderer<Event, String>(Event::getEventdate, "dd/mm/yyyy") same error I've tried to update my project to Vaadin v23 and v24, and had no luck as well.

Any suggestions would be appreciated, I'm stuck with this and couldn't find any answer online

Upvotes: 2

Views: 91

Answers (1)

cfrick
cfrick

Reputation: 37073

Date (what you are using, and if can you, shoudn't - check out java.time) is not LocalDate, what the renderer expects. The former is date plus time from the ancient beginnings of Java and the later is just a date.

So you have to either provide a getter that does the transformation in your Event class or you have to do it in the function passed down to the LocalDateRenderer.

Upvotes: 3

Related Questions