I have decided to modify an application that I created 2 years ago in Vaadin 23.1 and upgrade it with the latest Vaadin version (24.6.0). When I loaded my code to IDE, I got a number of compilation errors. Those errors are caused by deprecation of some classes and methods.
I fixed most of them, except one type that I am confused about.
I have a Grid and five out of eight columns of it has renderers. In the v.23 I used default constructors for it and it worked fine for me. Now, default constructor is no longer available and I have to use one of four parametrized constructors defined in https://vaadin.com/api/platform/24.5.4/com/vaadin/flow/data/renderer/ComponentRenderer.html
I did not understand how It works and wasn’t able to find examples in the documentation.
For example, my grid displays information about books and I have I need a renderer for book authors column, that will display authors as unordered list. I have this class:
public class AuthorListRenderer extends ComponentRenderer<UnorderedList, Book> {
@Override
public UnorderedList createComponent(Book source) {
Set<Author> authors = source.getAuthors();
ListItem[] items = new ListItem[authors.size()];
int i = 0;
for (Author author : authors) {
String item = ((author.getFirstName() == null) ? "" : (author.getFirstName() + " "))
+ author.getLastName() + ((author.getNickName() == null) ? "" : (" (" + author.getNickName() + ")"));
ListItem listItem = new ListItem(item);
listItem.getStyle().set("font-style", "italic");
listItem.getStyle().set("white-space", "normal");
items[i++] = listItem;
}
return new UnorderedList(items);
}
}
To fix the error I am adding this constructor:
public AuthorListRenderer(SerializableFunction<Book, UnorderedList> componentFunction) {
super(componentFunction);
}
But now I need to replace this line:
this.booksTable.addColumn(new AuthorListRenderer());
and I can’t figure out what kind of function I need to create for the new constructor.
If someone can clarify it for me or at least provide a link to the proper section of the manual, I will appreciate it greatly.