Execute code on window close in GWT

前端 未结 2 1376
刺人心
刺人心 2020-12-05 16:38

I\'d like to do something like this:

Window.addWindowClosingHandler(new Window.ClosingHandler() {

    @Override
    public void onWindowClosing(ClosingEven         


        
相关标签:
2条回答
  • 2020-12-05 17:12

    You want to look into Window.Confirm for this kind of functionality.

    You can read up on it here: gwt.user.client.Window

    0 讨论(0)
  • 2020-12-05 17:14

    There need to be two handlers, one Window.ClosingHandler and one CloseHandler. See below. This will make sure, if 'cancel' is clicked in the dialog, the CloseHandler isn't triggered. But if 'ok' is clicked, the CloseHandler is executed and will run the necessary code. This could be used for releasing db locks, neatly closing open sessions, etc.

    Window.addWindowClosingHandler(new Window.ClosingHandler() {
    
        @Override
        public void onWindowClosing(ClosingEvent event) {
            event.setMessage("You sure?");
        }
    });
    
    Window.addCloseHandler(new CloseHandler<Window>() {
    
        @Override
        public void onClose(CloseEvent<Window> event) {
            //Execute code when window closes!
        }
    });
    
    0 讨论(0)
提交回复
热议问题