Run window close code in GWT

I would like to do something like this:

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 to capture input from a dialog box?

+6
java events gwt
source share
2 answers

There must be two handlers: one Window.ClosingHandler and one CloseHandler . See below. This will make sure that the Cancel button is clicked in the dialog box, that CloseHandler does not start. But if you click "ok", CloseHandler executes and runs the necessary code. This can be used to release db locks, gently close 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! } }); 
+6
source share

You want to look in Window.Confirm for this kind of function.

You can read here: gwt.user.client.Window

0
source share

All Articles