Reputation: 2089
I have a regular wicket page and I need to catch and event when we navigate away from that page OR the page is destroyed either would work.
I have tried to override all sensable sounding methods none of them were triggered.
Is there an easy way to do this? Registering the page to some listener would work just as well.
Thank you very much!
Upvotes: 1
Views: 716
Reputation: 2089
I've figured I'll post the solution here so we have one on SO as well.
private class ProcessAfterCloseBehavior extends AbstractDefaultAjaxBehavior {
@Override
public void renderHead(Component component, IHeaderResponse response) {
super.renderHead(component, response);
response.render(new OnDomReadyHeaderItem("window.onbeforeunload = function (e) {"
+ getCallbackScript() + "};"));
}
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
attributes.setAsynchronous(false);
}
@Override
protected void respond(AjaxRequestTarget target) {
//Do whatever you need to do.
}
}
Upvotes: 3