在 GWT 中关闭窗口时执行代码 [英] Execute code on window close in GWT

查看:23
本文介绍了在 GWT 中关闭窗口时执行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的事情:

Window.addWindowClosingHandler(new Window.ClosingHandler() {

    @Override
    public void onWindowClosing(ClosingEvent event) {
        event.setMessage("Really?");

        // If user clicks 'ok' in the dialog, execute code below. Else skip the code and return to window.

        // CODE that does stuff goes here.
    }
});

如何从对话框中捕获输入?

How do I capture the input from the dialog?

推荐答案

需要两个处理程序,一个 Window.ClosingHandler 和一个 CloseHandler.见下文.这将确保,如果在对话框中单击取消",则不会触发 CloseHandler.但是,如果单击确定",则执行 CloseHandler 并将运行必要的代码.这可用于释放数据库锁,整齐地关闭打开的会话等.

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!
    }
});

这篇关于在 GWT 中关闭窗口时执行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆