0

我最近搬到 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;
        }
    }
}
4

0 回答 0