0

I have a web app that uses GXT (version 1.2.2) grids extensively. I'd like to warn the user if they make changes but don't save.

When I use the grid in a popup dialog, the only way for the user to leave is via a button (either Close or OK). If I add a SelectionListener to the Close button, I can do my "isDirty()" check and warn the user.

If I am not using a dialog, the restriction for leaving the page isn't there. The user can click on a side menu, select a different tab, hit a refresh or next page button that we have on each page. I could listen for an event on everyone of those, but is there an easier way? Something like a "before unload" event that gets fired?

2 Answers 2

0

Window.addCloseListener

Or in GWT 1.6:

Window.addCloseHandler

You cannot prevent the window from closing, but you can prompt the user to click cancel which will leave the page open. You can also perform a last-chance save operation after the user chooses to confirm the window close, but before your page is unloaded.

2
  • I tried this, but it didn't work, I assume since the window isn't closing. I'm just going to another grid or tab or page. Apr 10, 2009 at 20:28
  • I see. If the Grid is indeed unloading, then your only hope is hooking the onDetach() method on the the Widget. There's no listener so you'd have to overload it within a subclass. If the tab is changed, but the grid remains hidden, then you're completely out of luck and must listen to everything. Apr 10, 2009 at 20:41
0

Try this:

Window.addListener(Events.Close,
     new Listener<ComponentEvent>() {
          public void handleEvent(ComponentEvent be) {
                //Do something
          }
});

or

Window.addListener(Events.Detach,
         new Listener<ComponentEvent>() {
              public void handleEvent(ComponentEvent be) {
                    //Do something
              }
    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.