Vaadin Grid DateRenderer not appliable

David Artmann Source

I have a Grid in a Vaadin application. For one column I want to apply a DateRenderer. The following problem occurs:

enter image description here

What am I doing wrong? The example from the book of Vaadin is doing it like I do.


I got the same result as the answers to this question suggest. My working code (with several renderers):

final Grid<Signature> grid = new Grid<>(Signature.class);
grid.addColumn("createdTime", new DateRenderer("%1$td.%1$tm.%1$tY %1$tH:%1$tM:%1$tS"))
grid.addColumn(this::createCertificateLabel, new ComponentRenderer())
        .setDescriptionGenerator((DescriptionGenerator<Signature>) signature -> bundle.getString("certificateSerialNumber"));
grid.addColumn(this::createLink, new ComponentRenderer())


answered 6 months ago Dawid Fieluba #1

You can do it in addColumn() function which takes AbstractRenderer while setRenderer() excepts Renderer.

grid.addColumn( "myColumn", new DateRenderer( ... ) )

I guess you can also try doing it this way, but I haven't tested it (as DateRenderer implements Renderer<Date>):

column.setRenderer( (Renderer)new DateRenderer( ... ) );

answered 6 months ago Steffen Harbich #2

Let's have a look at the signature: Column<T, ?> getColumn(String columnId). It doesn't really know what's the second type parameter of your column because it could be anything. So applying a renderer by method Column<T, V> setRenderer(Renderer<? super V> renderer) expects an inferred renderer of type Renderer<? super ?> which I think can not be fulfilled.

Solution 1: Cast column to appropriate type like

((Grid.Column<YourBean, Date>) grid.getColumn("xyz")).setRenderer(new DateRenderer())

This will give you a compile warning due to unchecked cast. I think you could also cast to Column without type arguments but this will give you warnings, too.

Solution 2: As avix already pointed out in his answer, passing the renderer in the addColumn method is easier.

grid.addColumn(item -> someExpressionThatReturnsDate, new DateRenderer());

comments powered by Disqus