简体   繁体   中英

Vaadin popup should show and hide in the click event makes no appear popup

Having a

  public void buttonClick(ClickEvent event) {
             MyPopup popup = new MyPopup();
             getWindow().addWindow(popup);
             log.warn("Added POPUP");
    //lot of method calling here then
         getWindow().removeWindow(popup);
             log.warn("Removed Popup");
}

I would expect to show a popup window and after some milisecundom (after the expensive method calls) it should hide itself. The log says :

2014-02-19 15:26:51 WARN  xyzClass:82 - Added POPUP
2014-02-19 15:26:51 WARN  xyzClass:135 - Removed Popup

But the truth is that there is no popup showing here.

If i only show it, and not remove it later (the popup will show) public void buttonClick(ClickEvent event) { MyPopup popup = new MyPopup(); getWindow().addWindow(popup); log.warn("Added POPUP"); //lot of method calling here then log.warn("Removed Popup"); }

My main reason for this i want to achieve a glasspanel/loading screen functionality @ Vaadin, and not had found better solution yet. Any solution/description why the popup not shown up i would appreciate

Just do not have time to render it. You add it and immediately remove. Try this approach, for example:

private MyPopup popup;
public void buttonClick(ClickEvent event) {
    Thread workThread = new Thread() {
        @Override
        public void run() {         
            // some initialization here 
            getWindow().removeWindow(popup);
        }
    };
   workThread.start();             
   popup = new MyPopup();
   getWindow().addWindow(popup);
}

Depending on Vaadin version you can make use of ICEPush plugin (Vaadin 6) or built-in feature called Server Push (Vaadin 7).

public void buttonClick(ClickEvent event) {
    MyPopup popup = new MyPopup();
    getWindow().addWindow(popup);
    log.warn("Added POPUP");
    // start background thread with ICEPush or ServerPush
}

// Background thread in a separate class
// update UI accordingly when thread finished the job
    getWindow().removeWindow(popup);
    log.warn("Removed Popup");

Thanks to it you can move your time-consuming operations to another class thus decouple your business logic from the presentation layer. You can find examples of usage in the links above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM