我正在使用 vaadin-spring-boot-starter 21.0.7 开发一个新的应用程序,试图在网格中呈现训练数据库信息。我想要列表中的第一列是一个Active/Inactive的复选框,但我无法弄清楚如何完成。我看到的所有示例都是针对 Vaadin 7 或 8 的。大部分当前代码位于 MainView.java 中,链接在 https://github.com/gregoryleblanc/ealOperators/tree/vaadin。
grid.addComponentColumn(myBean -> {
Checkbox checkbox = new Checkbox();
checkbox.setValue(true); // this you must handle
checkbox.addClickListener(e -> {
// todo
}
return checkbox;
});
可以用方法引用代替lambda表达式
grid.addComponentColumn(this::createCheckboxComponent);
private Component createCheckboxComponent(MyBean myBean) {
Checkbox checkbox = new Checkbox();
// code here
return checkbox;
}
我正在使用一些超级老的Vaadin版本,但我想最新版本也应该适用相同的解决方案,这是我通常的做法:
String
的列ButtonRenderer
(column.setRenderer
)渲染器和事件监听器,允许我处理用户的点击操作font-family
并在网格上进行配置setCellStyleGenerator
)String.valueOf((char) FontAwesome.CHECK_SQUARE_O.getCodepoint())
String.valueOf((char) FontAwesome.SQUARE_O.getCodepoint())
使用较新版本的Vaadin可能有更简单的方法。然而,这种方法仍然有效。