Reputation: 61
How to defeat IE and Firefox dialog popup when trying to setResponsePage() from a wicket modalWindow per below. Dialog popup demands an answer to: "This page is asking you to confirm that you want to leave - data you have entered may not be saved."
AjaxLink signInContainer = new AjaxLink("signInContainer") {
@Override
public void onClick(AjaxRequestTarget target) {
target.appendJavascript("Wicket.Window.unloadConfirmation = false;");
modalWindow.close(target);
setResponsePage(SignInPage.class);
modalWindow.close(target);
}
};
-Rich
Upvotes: 6
Views: 7299
Reputation: 223
In wicket 6.x and above you can simply set showUnloadConfirmation
to false
:
final ModalWindow modalWindow = new ModalWindow("modalWindow");
modalWindow.showUnloadConfirmation(false);
Upvotes: 10
Reputation: 10896
EDIT: This is a hack, use the alternative described in my other answer.
Try this:
public void onClick(AjaxRequestTarget target) {
modal.close(target);
CharSequence url = urlFor(HomePage.class, new PageParameters("gone=true"));
target.appendJavascript("window.location='" + url + "';");
}
Upvotes: 0
Reputation: 10896
target.appendJavascript("Wicket.Window.unloadConfirmation = false;");
doesn't work because it must run before modal.show(target);
.
You could either prepend, instead of append, the script, when opening the window:
add(new AjaxLink<Void>("show") {
@Override
public void onClick(AjaxRequestTarget target) {
target.prependJavascript("Wicket.Window.unloadConfirmation = false;");
modal.show(target);
}
});
or add a behavior, to execute it on onload
:
modal.add(new AbstractBehavior() {
@Override
public void renderHead(IHeaderResponse response) {
response.renderOnLoadJavascript("Wicket.Window.unloadConfirmation = false;");
}
});
But, it must be called before opening the modal window, not when navigating away from the page (setResponsePage()
).
Upvotes: 9
Reputation: 5150
I believe setResponsePage()
should be accompanied by some other methods to behave properly. For example, I often include setRedirect(true)
when using this technique. I'm not sure what all is going on behind the scenes there, but perhaps try that.
Upvotes: 0