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.

Disable Layout in button click event

Marina Vohs
5 years ago Aug 05, 2016 3:50pm
Marco Collovati
5 years ago Aug 05, 2016 4:15pm

Hi Marina,
if yuo have Push enabled you can force a push to send ui changes to the client

@Override
public void buttonClick(final ClickEvent event) {
    getView().setEnabled(false);
[b]    push();[/b]
    doSomething();
    getView().setEnabled(true);
}

With push enabled you can also run doSomething() and enable view in a background thread; in this case you shoul perform ui modifications through UI.access method.

If cannot enable push you should have two client-server roundtrips; for example you can register a javascript function that performs the job while the button click listeners disables the view and invokes that function.

button.addClickListener(e -> {
    getView().setEnabled(false);
    getUI().getPage().getJavaScript().execute("doTheJob()");
});

getUI().getPage().getJavaScript().addFunction("doTheJob", arguments -> {
      doSomething();
      getView().setEnabled(true);
});

HTH
Marco

 

Marina Vohs
5 years ago Aug 08, 2016 11:16am