英文:
Vaadin grid becomes empty, when using CheckboxRenderer
问题
Vaadin版本是8.10.1
添加插件:
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>grid-renderers-collection-addon</artifactId>
<version>2.7.0</version>
</dependency>
在表格中定义渲染器如下:
CheckboxRenderer renderer = new CheckboxRenderer<>(Payment::setSelectedToMultiAction);
paymentGrid.addColumn(Payment::getSelectedToMultiAction)
.setRenderer(renderer)
.setCaption("Selection");
但是表格显示为空。在Chrome的js控制台中没有错误:
如果我们移除渲染器,一切都会显示出来。
CheckboxRenderer renderer = new CheckboxRenderer<>(Payment::setSelectedToMultiAction);
paymentGrid.addColumn(Payment::getSelectedToMultiAction)
// .setRenderer(renderer)
.setCaption("Selection");
控件在vaadin-maven-plugin运行期间处理:
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.version}</version>
<configuration>
<webappDirectory>${basedir}/resources/VAADIN/widgetsets</webappDirectory>
<hostedWebapp>${basedir}/resources/VAADIN/widgetsets</hostedWebapp>
</configuration>
<executions>
<execution>
<goals>
<!--<goal>clean</goal>
<goal>resources</goal>-->
<goal>update-theme</goal>
<goal>update-widgetset</goal>
<goal>compile-theme</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
英文:
Vaadin version is 8.10.1
Adding the addon:
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>grid-renderers-collection-addon</artifactId>
<version>2.7.0</version>
</dependency>
and in the grid defining the renderer like that:
CheckboxRenderer renderer = new CheckboxRenderer<>(Payment::setSelectedToMultiAction);
paymentGrid.addColumn(Payment::getSelectedToMultiAction)
.setRenderer(renderer)
.setCaption("Selection");
But the grid shown empty. With no error in Chrome's js console:
If we remove the renderere, everything is displayed.
CheckboxRenderer renderer = new CheckboxRenderer<>(Payment::setSelectedToMultiAction);
paymentGrid.addColumn(Payment::getSelectedToMultiAction)
// .setRenderer(renderer)
.setCaption("Selection");
The widget is handled during the vaadin-maven-plugin run:
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.version}</version>
<configuration>
<webappDirectory>${basedir}/resources/VAADIN/widgetsets</webappDirectory>
<hostedWebapp>${basedir}/resources/VAADIN/widgetsets</hostedWebapp>
</configuration>
<executions>
<execution>
<goals>
<!--<goal>clean</goal>
<goal>resources</goal>-->
<goal>update-theme</goal>
<goal>update-widgetset</goal>
<goal>compile-theme</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
答案1
得分: 1
我成功使用 Vaadin 8.1 中的 ComponentRenderer
,而不是 grid-renderers-collection-addon
中的 CheckboxRenderer
。
paymentGrid.addComponentColumn(payment -> {
CheckBox multiselected = new CheckBox();
multiselected.addValueChangeListener(event -> {
payment.setSelectedToMultiAction(event.getValue());
if (event.getValue()) {
selectedPayments.add(payment);
} else {
selectedPayments.remove(payment);
}
showButtons();
});
return multiselected;
});
英文:
I succeed with using ComponentRenderer
from Vaadin 8.1, not the CheckboxRenderer
from grid-renderers-collection-addon
paymentGrid.addComponentColumn(payment -> {
CheckBox multiselected = new CheckBox();
multiselected.addValueChangeListener(event -> {
payment.setSelectedToMultiAction(event.getValue());
if (event.getValue()) {
selectedPayments.add(payment);
} else {
selectedPayments.remove(payment);
}
showButtons();
});
return multiselected;
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论