我想做这样的事情:
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.
}
});
如何从对话框中捕获输入?
答案 0 :(得分:6)
需要两个处理程序,一个Window.ClosingHandler
和一个CloseHandler
。见下文。这将确保,如果在对话框中单击“取消”,则不会触发CloseHandler
。但如果单击“确定”,则执行CloseHandler
并运行必要的代码。这可以用于释放数据库锁,整齐地关闭打开的会话等。
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!
}
});
答案 1 :(得分:0)
您想要查看Window.Confirm以了解此类功能。
你可以在这里阅读: gwt.user.client.Window