gpt4 book ai didi

java - "Live"Vaadin 应用程序 - 如何更新浏览器 View

转载 作者:行者123 更新时间:2023-12-02 03:21:20 26 4
gpt4 key购买 nike

我有一个 Vaadin 应用程序,我喜欢“实时”,这样当不同的人打开该应用程序时,他们可以直接看到另一个人所做的更改,而无需刷新页面。

我该怎么做?

该应用程序当前由两个面板组成,其中包含可以拖放的组件。

现在我喜欢在所有打开的浏览器 View 中看到拖放操作,这样当 A 拖放某些内容时,它会自动显示在其他 View 中。

我目前只能在其他人刷新 View 时才能做到这一点(我使用 Vaadin 7.6.6)

更新

@Push
private static final class MyPanel extends Panel implements BroadcastListener {
@Override
public void attach() {
Broadcaster.register(this);
super.attach();
}

@Override
public void detach() {
Broadcaster.unregister(this);
super.detach();
}

@Override
public void receiveBroadcast(BroadcastMessage message) {
System.out.println("BROADCOAST " + message);
}
}

private Panel createTaskPanel(Status status) {
Panel tasks = new MyPanel();
tasks.setHeight("500px");

VerticalLayout taskLayout = new VerticalLayout();
taskLayout.setSpacing(true);
taskLayout.setMargin(true);
TaskContainer.get().getTasks().filter(task -> task.getStatus() == status).map(TaskComponent::new)
.map(TaskComponent::getDragAndDrop).forEach(taskLayout::addComponent);

DragAndDropWrapper wrapper = new DragAndDropWrapper(taskLayout);
wrapper.setDropHandler(new DropHandlerImplementation(status, taskLayout));
tasks.setContent(wrapper);
return tasks;
}

最佳答案

您需要两件事:

  1. 启用服务器推送,以便将服务器更改推送到客户端
  2. 通过某种方式将您的更改广播到其他 UI 实例。

这里有一个更详细的答案示例

Vaadin: get reference of UI to change data

关于java - "Live"Vaadin 应用程序 - 如何更新浏览器 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39568055/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com