tags:

views:

365

answers:

3

I'd 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 do I capture the input from the dialog?

+1  A: 

You want to look into Window.Confirm for this kind of functionality.

You can read up on it here: gwt.user.client.Window

NebuSoft
Well, i've tried that, but despite what you choose in the confirm dialog, it will close the window. I want the window to stay open when the cancel button is pressed.I can for example do a if(Window.confirm("Really"){ do stufff }else{ stop closing window} the only way I know how to stop it from closing is to call the setMessage() method on the event. This will pop up yet another dialog..... which if I click cancel will stop the window from closing, but that's really ugly. I want to be able to use just one dialog.
stuff22
A: 

an example for close event

Window.addWindowCloseListener(new WindowCloseListener() {

            @Override
            public String onWindowClosing() {
                // TODO Auto-generated method stub
                return "Ta-ta for now!";//show a message
            }

            @Override
            public void onWindowClosed() {
                // TODO Auto-generated method stub
               // If user wishes to navigate away from the page do some stuff

            }
        });
Kerem
No dice. WindowsCloseListener is deprecated.
stuff22
A: 

I figured it out. Here's the magic formula. There need to be two handlers, one Window.ClosingHandler and one CloseHandler. See below. This will make sure that 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 I want to run when window closes, such as 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!
            }
        });
stuff22
This for some reason doesn't work as well in IE.
stuff22