I have a Grid in a Vaadin application. For one column I want to apply a DateRenderer
.
The following problem occurs:
What am I doing wrong? The example from the book of Vaadin is doing it like I do.
UPDATE
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.setSelectionMode(Grid.SelectionMode.SINGLE);
grid.setSizeFull();
grid.setColumns();
grid.addColumn("type").setCaption(bundle.getString("type"));
grid.addColumn("filename").setCaption(bundle.getString("filename"));
grid.addColumn("createdTime", new DateRenderer("%1$td.%1$tm.%1$tY %1$tH:%1$tM:%1$tS"))
.setCaption(bundle.getString("creationDate"));
grid.addColumn(this::createCertificateLabel, new ComponentRenderer())
.setCaption(bundle.getString("certificate"))
.setDescriptionGenerator((DescriptionGenerator<Signature>) signature -> bundle.getString("certificateSerialNumber"));
grid.addColumn(this::createLink, new ComponentRenderer())
.setCaption(bundle.getString("action"));
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());