Disable Layout in button click event

How can I disable a layout from inside the button click event? I want to do something like this:

    @Override
    public void buttonClick(final ClickEvent event) {
        getView().setEnabled(false);
        doSomething();
        getView().setEnabled(true);
    }

But if I try it like this the view will not be disabled. All the UI stuff will be done after the buttonClick action is finished.
markAsDirty() is not working either.

Can someone of you help me?
Thank you very much.
Marina

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

Hi Marco

Unfortunately we cannot enable push for our application. But the second way with the javaScript function is working like a charm.

Thank you very much
Marina