【问题标题】:How can I clean up/remove the content in AppLayout in Vaadin 14?如何在 Vaadin 14 中清理/删除 AppLayout 中的内容?
【发布时间】:2020-11-23 11:38:42
【问题描述】:

如何在 Vaadin 14 中显示静态组件?每次更新页面时,我都会收到错误消息。

在这种情况下,startStopYOLO, cameras, darknet, configuration, weights, thresholds, realTimeCameraImage, layout 都是static

// Content
if(layout == null) {
    layout = new VerticalLayout();
    layout.add(new FormLayout(startStopYOLO, cameras, darknet, configuration, weights, thresholds));
    layout.add(realTimeCameraImage);
    layout.setAlignItems(Alignment.CENTER);
}
setContent(layout); // Here I get the error:

错误是:

Can't move a node from one state tree to another. If this is intentional, first remove the node from its current state tree by calling removeFromTree

所以我需要先清理content。我如何在 Vaadin 14 中做到这一点?

【问题讨论】:

    标签: java vaadin vaadin14


    【解决方案1】:

    该错误已经在一定程度上说明了问题:Can't move a node from one state tree to another

    或者更确切地说:您不能在不同的 UI 上共享元素。所以不行 static,没有单例,... - 你必须创造新鲜的元素。

    元素成为一个 UI 的场景图的一部分(状态树 从错误消息中)一旦他们得到附加。此时 Vaadin 内部确保该元素尚未附加到 不同的 UI(根)(可以在一个 UI 中移动元素,这 也可以通过将其添加到同一 UI 的不同父级来工作)。

    如果您已共享状态,例如服务器,您将必须创建 每个 UI 的元素,然后将此状态与 @PushUI.access 或类似的。

    【讨论】:

    • 不,可以将组件作为静态组件。
    • 当然,但仅适用于以下边界情况:只要一个客户端恰好持有静态元素;例如按照错误消息中的建议步骤(首先删除元素)。但是,如果这几乎不是您的用例。
    • @DanielMårtensson 可能,但您仍然不能同时多次添加单个组件。
    • @kscherrer 所以我不能向多个用户显示图像?
    • @DanielMårtensson 当然可以。您创建不同的图像元素,它们都指向同一个服务器资源/链接/...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-06
    • 2021-11-25
    • 2011-08-07
    • 2011-05-21
    • 2020-06-08
    • 1970-01-01
    • 2021-07-28
    相关资源
    最近更新 更多