0

From java swing I'm used to show modal dialogs for long-running tasks. The background thread updates status labels and progress bar on the dialog from time to time.

With vaadin modal windows, I cannot change anything from the background thread, I can't even close the window.

Is this expected behavior or am I doing it wrong?

Edit: Actually I can't seem to update a window even if it is non-modal.

Window window = new Window();
// window.setModal(true);

VerticalLayout layout = new VerticalLayout();
Label label = new Label("0");
layout.addComponent(label);
window.setContent(layout);
window.center();

new Thread(() -> {
  try
  {
    Thread.sleep(1000);
    System.out.println("update 1");
    UI.getCurrent().access(() -> label.setValue("1"));
    Thread.sleep(1000);
    System.out.println("update 2");
    UI.getCurrent().access(() -> label.setValue("2"));
    Thread.sleep(1000);
    System.out.println("update 3");
    UI.getCurrent().access(() -> label.setValue("3"));
    Thread.sleep(1000);
    System.out.println("close");
    UI.getCurrent().access(() -> window.close());
  }
  catch(InterruptedException e)
  {
    System.out.println(e);
  }
}).start();

UI.getCurrent().addWindow(window);

Edit 2: I just stumbled across the vaadin push concept, which is probably what I am missing here.

Reto Höhener
  • 5,419
  • 4
  • 39
  • 79

1 Answers1

0

The reason was that I did not have vaadin push configured.

After adding the vaadin-push dependency and the @Push annotation to my main UI, it started to work.

Now onwards to the next problem...

Community
  • 1
  • 1
Reto Höhener
  • 5,419
  • 4
  • 39
  • 79