我正在尝试修改 2.5 年前使用 Vaadin 23 创建的应用程序。 我已升级到 Vaadin 24.6.0,但由于弃用多个函数和类而出现大量编译错误。我修复了其中的大部分问题,但仍然遇到一种类型的错误 - ComponentRenderer 的默认构造函数不再存在。我的应用程序显示一个包含书籍信息的网格,并且每一列都是专门呈现的。 这是渲染器之一的示例,它创建了一个无序列表的书籍作者列表。
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);
}
}
现在,我需要使用四个参数化构造函数之一,而不是默认构造函数,但我不太明白这些 SerializedFunction 或 serializedSupplier 是如何工作的。我在 Vaadin 文档中找不到任何解释或示例。 如果有人可以向我解释,我将不胜感激。
不同的c'tors基本上提供以下功能:
详细信息可以在网格/组件文档中找到 渲染器 和 JavaDoc
ComponentRenderer
例如(这里很明确,所以没有 λ)
class AuthorListRenderer extends ComponentRenderer<UnorderedList, Book> {
AuthorListRenderer() {
super(new SerializableFunction<Book, UnorderedList>() {
@Override
UnorderedList apply(Book book) {
new UnorderedList(
book.authors.collect { new ListItem(it.toString()) } as ListItem[]
)
}
})
}
}