0

我的应用程序的 onModuleLoad() 中有以下代码:

    Window.addWindowClosingHandler(new ClosingHandler() {
        @Override
        public void onWindowClosing(ClosingEvent event) {
            event.setMessage("If you choose to close, application will sign out");
        }   
    });

    //sign out on close
    Window.addCloseHandler(new CloseHandler<Window>() {
        @Override
        public void onClose(CloseEvent<Window> event) {
            sendLogout();
        }
    });

sendLogout() 函数如下所示:

// Set up the callback object.
    AsyncCallback<String> callback = new LogoutCallback(this);
    // Make the call to the survey service.

    SurveySystemService.Util.getInstance().logout(details, callback);

“细节”是一些对象。

关闭窗口时它工作得很好,但是如果我尝试刷新页面,它不会注销。我的想法是,由于调用是异步的,因此在重新启动模块之前它没有完成将消息发送到服务器。

我尝试过: 1. 在 onClose 方法中创建和调用回调。2. 使用计时器检查是否拨打了电话。3. Endless loos 检查与上述相同(我绝望了)。

在所有这些解决方案中,程序都会到达回调创建,但服务器从未收到任何东西。

有什么帮助吗?

4

1 回答 1

0

您可以在页面首次加载时随时调用注销。由于 Web 的无状态特性,GWT 应用程序不会知道有人点击刷新或只是导航到页面之间的区别。

您可以将 ID 变量存储在会话存储中,该变量应一直保留到浏览器窗口或选项卡关闭为止。如果在应用程序启动时 ID 变量存在于会话存储中,您可以使用它来触发注销。

于 2012-06-04T23:49:18.633 回答