1

I understand that Vaadin 8.1.0 will include a new LocalDateRenderer to work with Java 8's new date LocalDate 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 displayed. If I use the same code but instead of LocalDate I do it for a Long but instead of extends AbstractRenderer I extend NumberRenderer with my own code then it works.

This lead me to the documentation 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 in the documentation it's not clear which class is which when they refer to TextRenderer since they use the same name to to be different things...

Stephane Grenier
  • 15,527
  • 38
  • 117
  • 192
  • 1
    FYI, Vaadin Framework 8.1.0 Alpha 2 [is available](http://vaadin.com/releases). You could peek at their source code. – Basil Bourque Mar 29 '17 at 03:37
  • I tried to build similar renderer, but gave up after several hours and decided to wait 8.1. I don't have hurry, so I'll wait 8.1. to become out officially, and show my dates as strings (barbaric, I know..) meanwhile .. – Jukka Nikki Mar 29 '17 at 10:02
  • Just a link to issue which contains discussion of topic https://github.com/vaadin/framework/issues/8377#issuecomment-290049482 – Jukka Nikki Mar 29 '17 at 11:09
  • If you just want to display them in some specific format, you could have a temporary workaround till 8.1.0 using [converters](http://stackoverflow.com/questions/38862644/vaadin-grid-how-to-use-bean-with-localtime-field-in-line-based-editor). If you want to do the renderer for some other reason, please ignore my comment – Morfic Mar 29 '17 at 13:39
  • I looked at the code and I gave up after a few hours. I can't find the missing link... – Stephane Grenier Mar 29 '17 at 16:08
  • **UPDATE:** Vaadin 8.1 is shipping with Vaadin Grid column renderers for `LocalDate`, `LocalTime`, and `LocalDateTime`. Mysteriously, they did not implement renderers for the more useful `Instant`, `OffsetDateTime`, and `ZonedDateTime` java.time classes. You can implement such renderers yourself rather easily as an Add-On by writing three class files. See [my Question](https://stackoverflow.com/q/45944529/642706) and [my Answer](https://stackoverflow.com/a/46062273/642706). – Basil Bourque Sep 05 '17 at 20:20
  • See my [*TimeColumnRenderers* project on BitBucket](https://bitbucket.org/basil_bourque/timecolumnrenderers) for classes `InstantRenderer`, `OffsetDateTimeRenderer`, and `ZonedDateTimeRenderer`. – Basil Bourque Oct 18 '17 at 22:08

1 Answers1

0

If your compiler can't resolve AbstractRendererConnector<T> to a type, you must be missing a dependency. If you are using Maven, you can add the following dependency, assuming that you have the vaadin-bom in your <dependencyManagement> section.

    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-client</artifactId>
    </dependency>

This artifact is not included by default in most of the Vaadin archtetypes.

Also be careful: there are two Renderer interfaces, one in com.vaadin.client.renderers and one in com.vaadin.ui.renderers. Your covariant return in LocalDateRendererConnector.getRenderer() won't work because AbstractRendererConnector<T> implements a different Renderer interface.

Alejandro C De Baca
  • 888
  • 2
  • 9
  • 16