Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Need help connecting custom LocalDateRenderer

Stephan Grenier
5 years ago Mar 23, 2017 3:09am

I understand that Vaadin 8.1.0 will include a new LocalDateRenderer to work with Java 8's new date libraries but in the meantime I'm trying to setup my own custom LocalDateRenderer. I've got it mostly working in that it's all hooked up but based on the documentation I need to setup an AbstractRendererConnector but there's no such class...

The following code is all in my main UI class (for testing purposes):

private void setupGrid(Grid<Dog> grid)
{
    grid.addColumn(dog -> dog.getBirthday(), new LocalDateRenderer()).setCaption("Birthday");
}
    
class LocalDateRenderer extends AbstractRenderer<Object, LocalDate>
{
    public LocalDateRenderer() 
    {
        super(LocalDate.class, "");
    }

    @Override
    public JsonValue encode(LocalDate localDate) 
    {
        return encode(DateTimeFormatter.ofPattern("MMM dd, YYYY").format(localDate), String.class);
    }
}

I have confirmed that the LocalDateRenderer is called by adding logging statements, however on the grid no values are presented. I tried as hard as I can't figure out how to get it to display. If I use the same logic but instead of say for a LocalDate I do it for a Long but instead of extends AbstractRenderer I extend NumberRenderer and put in my own custom logic then it works.

This lead me down the documentation linked above where I need to setup the Renderer with a AbstractRendererConnector but whenever I try to do this I get the compiler error saying that AbstractRendererConnector cannot be resolved to a type. And then of course I have a number of compiler errors (in the code below). My code for this (still in the main UI class) is:

@Connect(LocalDateRenderer.class)
class LocalDateRendererConnector extends AbstractRendererConnector<LocalDate> 
{
    @Override
    public LocalDateRenderer getRenderer() 
    {
        return (LocalDateRenderer) super.getRenderer();
    }
}

Any assistance with how to get it linked up so that it displays my actual dates would be greatly appreciated. Thank you.

Also a quick tip, in the linked documentation it would be nice if the names were different so it's clear which is referencing what. All the names are just TextRenderer so it's not clear when you want which class. I was hoping to just link it to TextRenderer on the client side but it wasn't clear which TextRenderer class was which in the user manual.