0

I have a Vaadin application, that I like to be "live", so that when different people have opened the application, they see changes made by another person directly, without refreshing their page.

How can I do this ?

The application consists currently of two panels, with components in them, which can be dragged and dropped.

Now I like to see a drag and drop in all open browser views, so that when person A has drag and dropped something, that this is automatically shown in the other views.

I currently can only make this, when the others are refreshing their view (I use Vaadin 7.6.6)

UPDATE

@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;
}
Emerson Cod
  • 1,990
  • 3
  • 21
  • 39

1 Answers1

2

You will need two things:

  1. Enable server push,so that server changes are pushed to the clients
  2. Some way to broadcast your changes to other UI instances.

Here a example of such a answer in more details

Vaadin: get reference of UI to change data

Community
  • 1
  • 1
André Schild
  • 4,592
  • 5
  • 28
  • 42
  • thanks for the answer - I have to admit, I don't really know, how to apply this. I have edited my post and included my component for which I tried. The *enter* method or *initialize* method does not exists for a panel for me. So what to use there ? My DropHandler calls the Broadcaster.broadcast method in the drop method – Emerson Cod Sep 19 '16 at 10:05
  • The `attach()`/`detach()` methods should just be fine for this. Isn't it receiving broadcasts at the moment? – André Schild Sep 19 '16 at 10:11
  • I receive the broadcasts, and if I add a new component in the `receiveBroadCast` method it works fine... but what must I do, to refresh the panels ? When a component has been drag and dropped, I remove the component from source panel and add it to the new panel. I tried this outside of the `receiveBroadCast` method and inside, but in neither cases the other view gets updated – Emerson Cod Sep 19 '16 at 10:29
  • it works partially. I have as caption of the panels the `componentCount` of the panel. This gets correctly updated, but I don't see the added/removed component in the panel. So something is happening... – Emerson Cod Sep 19 '16 at 10:36