我最近搬到Vaadin 14,现在正尝试使用com.vaadin.flow.component.gridpro
。
如果现在使用com.vaadin.flow.data.renderer.ComponentRenderer<>
渲染行详细信息,则在单击生成的详细信息时会收到以下错误消息(通知):
TypeError:无法读取未定义的属性“ localName”
虽然没有任何Java异常,但Chromium已记录以下内容:
client-FD21A18FF7B71…CC75CC.cache.js:198 TypeError: Cannot read property 'localName' of undefined
vaadin-grid-pro-inli…g-mixin.js?84ef:176 Uncaught TypeError: Cannot read property 'localName' of undefined
at HTMLElement._isEditColumn (vaadin-grid-pro-inli…g-mixin.js?84ef:176)
at HTMLElement.eval (vaadin-grid-pro-inli…g-mixin.js?84ef:148)
我知道,使用com.vaadin.flow.component.grid.Grid
而不是com.vaadin.flow.component.gridpro.GridPro
不会发生这种情况,但是我的问题是使用GridPro
时如何摆脱此错误?
重新创建我的问题:
从原型创建一个新的Vaadin 14项目:
mvn -B archetype:generate -DarchetypeGroupId=com.vaadin -DarchetypeArtifactId=vaadin-archetype-application -DarchetypeVersion=LATEST -DgroupId=org.test -DartifactId=vaadin-app -Dversion=1.0-SNAPSHOT
将MainView.java
更改为此:
// import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.gridpro.GridPro;
import com.vaadin.flow.component.html.Label;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.PWA;
@Route
@PWA(name = "My Application", shortName = "My Application")
public class MainView extends VerticalLayout {
public MainView() {
GridPro<Foo> grid = new GridPro<>();
// Grid<Foo> grid = new Grid<>();
grid.addColumn(Foo::getBar).setHeader("Bar");
grid.setItemDetailsRenderer(
new ComponentRenderer<>(s -> {
VerticalLayout layout = new VerticalLayout();
layout.setSizeFull();
Label label = new Label(s.getBar());
layout.add(label);
return layout;
}));
add(grid);
grid.setItems(new Foo("Click me"));
}
private static class Foo {
private String bar;
private Foo(String bar) {
this.bar = bar;
}
public String getBar() {
return bar;
}
}
}