how can I know if the user has left the page in wicket?

ajax, java, javascript, wicket, wicket-1.5

Solution

Simply generate your browser onbeforeunload using https://cwiki.apache.org/WICKET/calling-wicket-from-javascript.html. In the callback you can then check the state of your form or page.

Problem

I am searching for a way to know when the user leaves the page and has not saved the changes then show wicket's modal(preferable but could be a confirmation box). Additional info: the solution should have minimal effects in code, because I have about 30 pages that will have the behavior, actually all my web pages extends from one called LayoutPage, something similar to this I tried with pure JavaScript solution like in this question, but the application send a lot of data via AJAX requests, so I couldn't determine a nice way to know if the data has been sent to the server Ihen I start to look in the source code of the `Form.class` of Wicket. It has a nice method called `isSubmitted()`; I could use it if I was able to know from wicket if the user is about to quit the page. I don't want to write a validation for each page in the system.

Original source

Related problems