Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

How to pass values from window back to a view

Andrej Kocen
6 years ago Jul 30, 2015 7:48am
Marko Grönroos
6 years ago Jul 30, 2015 11:43am

I'd say that the normal pattern to hande input done in a dialog window would be to have an "OK listener" or "save listener", or in Java 8 just a Consumer of the edited data type.

public class MyDialog extends Window {
    @FunctionalInterface
    public interface SaveListener {
        public void save(SomeDataModel modifiedData);
    }

    public MyDialog(SaveListener save) {
       ...
    }
}

Then use it for example:

SomeDataModel data;
...

MyDialog dlg = new MyDialog(data, (modifiedData) -> {
    data = modifiedData;
    Notification.show("Data changed");
});
UI.getCurrent().addWindow(dlg);

 

Andrej Kocen
6 years ago Jul 31, 2015 11:16am