tags:

views:

922

answers:

1

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?

A: 

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.

Mark Renouf
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.
CoverosGene
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.
Mark Renouf