Hi,
I am trying to use vaadin-grid component in my code. I tried to use the example source code to display grid item detail. But I have problems with ComponentRenderer. I am getting error: “The type ComponentRenderer is not generic; it cannot be parameterized with arguments <>” for the source code from example:
Grid grid = new Grid<>();
grid.setItems(people);
grid.addColumn(new ComponentRenderer<>(person → {
if (person.getGender() == Gender.MALE) {
return new Icon(VaadinIcons.MALE);
} else {
return new Icon(VaadinIcons.FEMALE);
}
})).setHeader(“Gender”);
Could you please help me with the error? Or is there any other option how to show item details for a grid item?
The code you posted doesn’t actually set the item details of a row, it only sets an icon component to a column. The error you are having is related to the fact that your Grid is not using generics:
// instead of
Grid grid = new Grid<>();
// it should be
Grid<Person> grid = new Grid<>();
thank you very much for your quick answer. The problem was that I used import from com.vaadin.ui.renderers.ComponentRenderer instead of com.vaadin.flow.data.renderer.ComponentRenderer.
But now I have another error: “Cannot infer type arguments for ComponentRenderer<>”
my code:
Grid<Person> grid = new Grid<>();
grid.setItemDetailsRenderer(new ComponentRenderer<>(Person::new));