Hi guys,
I try to use componentRenderer for one column in my grid. I have followed the instruction like in “book of vaadin” (chapter 5.5.3)
but my code is in error in my Eclipse IDE. My code below :
The method addColumn(ValueProvider<ComposantT,?>) in the type Grid<ComposantT> is not applicable for the arguments (new ComponentRenderer<>((<no type> ComposantT) -> { if ((ComposantT.getEpplSfam() == null))
{
return "";
} else
{
return ComposantT.getEpplSfam();
}}))
But I have an other error :
Cannot infer type arguments for ComponentRenderer<>
I think the issue probably is that you are trying to render a string, whereas ComponentRenderer renders components (as its name implies). For your purpose, you can use Vaadin’s label component like so:
gridComp.addColumn(new ComponentRenderer<>(ComposantT -> {
if (ComposantT.getEpplSfam() == null) {
return new Label("");
} else {
return new Label(ComposantT.getEpplSfam());
}
})).setHeader(new Html("<b>Code Famille<b>"));
And naturally, you’ll need to import com.vaadin.flow.component.html.Label
This is very likely to be the correct solution to OPs issue, however I wanted to mention that Label is based on the <label> element, and should therefore only be used for form field labels.
Use Span or Text instead to simply add some text to a layout.
gridComp.addColumn(new ComponentRenderer<>(ComposantT -> {
if (ComposantT.getEpplSfam() == null) {
return new Span("");
} else {
return new Span(ComposantT.getEpplSfam());
}
})).setHeader(new Html("<b>Code Famille<b>"));
This happens when it does not see the lambda returning a Component. Please check your lambda that it always returns something that extends Component.
You could also define the type parameters yourself (new ComponentRenderer<Component, ComposantT>(item -> ...)), then you’ll see better where exactly in your lambda it tries to return something that is not a Component.