我有一个GWT应用程序,它为CloseEvent注册一个CloseHandler。此处理程序在另一个类中调用logout()方法,该方法执行一些清理并调用RPC方法将用户从基础服务器应用程序中注销(GWT应用程序是Web服务器为中间层的客户端)。
以下是CloseHandler的代码:
Window.addCloseHandler(
new CloseHandler<Window>() {
@Override
public void onClose( CloseEvent<Window> event ) {
MainPresenter main = Client.this.context.getMainPresenter();
if (main != null) {
System.out.println("calling main.logout()..." );
main.logout();
System.out.println("back from logout()..." );
}
}
});
以下是logout()方法的代码:
public void logout() {
System.out.println("in logout()..." );
/*
* This callback method likely will not be executed because this
* logout method is going to be called as the browser window is
* closing. Consequently, the RPC call will not return. But if it
* does, simply ignore the return.
*/
AsyncCallback<UserOperationResult> callback = new AsyncCallback<UserOperationResult>() {
@Override
public void onFailure( Throwable caught ) {
// ignore
System.out.println("logout failed:" + caught);
caught.printStackTrace();
}
@Override
public void onSuccess( UserOperationResult result ) {
// ignore
System.out.println("result=" + result);
}
};
System.out.println("calling authentication service-> logout()..." );
this.context.getAuthenticationService().logout( MainLimsPresenter.this.context.getUser(), callback );
// stop the ping service
this.context.stopPingTimer();
System.out.println( "stopped ping timer..." );
this.context.stopBlockedTimer();
System.out.println("stopped blocked timer..." );
releaseRegistrations();
System.out.println("released registrations..." );
}
生成的输出如下:
mozilla/5.0 (windows nt 6.1; wow64; rv:18.0) gecko/20100101 firefox/18.0
closing... end session
calling main.logout()...
in logout()...
calling authentication service-> logout()...
stopped ping timer...
stopped blocked timer...
released registrations...
back from logout()...
正如您所看到的,RPC方法在应用程序完成之前就已被调用,但是没有来自Web服务服务的日志/调试消息,并且用户未从基础应用程序注销。所以RPC真的永远不会被调用。
直到最近升级到Firefox 21 才能正常工作。测试显示这适用于Firefox 9,15,16和17,但已停止使用版本18.0.2。它适用于Chrome(27)和IE9以及之前版本的Chrome和IE。
我尝试查看Firefox 18的更改列表,看看是否有什么我可以确定可能会影响RPC方法的调用,但是找不到任何明显的东西。
是否有其他人遇到此问题或有解决方法?
谢谢!
答案 0 :(得分:0)
你应该使用这个用于Firefox的closeHandler
Window.addCloseHandler(new CloseHandler<Window>() {
@Override
public void onClose(CloseEvent<Window> event) {
对于其他浏览器
Window.addWindowClosingHandler(new Window.ClosingHandler() {
@Override
public void onWindowClosing(ClosingEvent event) {