How to defeat browser dialog popup when calling Wicket setResponsePage() from modal window?
Asked Answered
T

4

6

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

Thornie answered 4/11, 2011 at 17:23 Comment(0)
M
10

In wicket 6.x and above you can simply set showUnloadConfirmation to false:

final ModalWindow modalWindow = new ModalWindow("modalWindow");
modalWindow.showUnloadConfirmation(false);
Moat answered 3/1, 2014 at 15:0 Comment(0)
E
9

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()).

Entebbe answered 30/12, 2011 at 13:28 Comment(2)
To use the latter approach in Wicket 6, Behavior should be used instead of AbstractBheavior, and since renderOnLoadJavaScript doesn't exist anymore, one would use response.render(JavaScriptHeaderItem.forScript("...", id));.Zany
OnDomReadyHeaderItemEntebbe
E
0

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 + "';");
}
Entebbe answered 4/11, 2011 at 19:56 Comment(2)
Would this bypass Wicket's built-in PageMap? Would there be any negative side effects?Yalu
This would be the same as opening a bookmarkable page from a static link or browser bookmark. I can't see how it could cause any problem.Entebbe
Y
0

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.

Yalu answered 5/11, 2011 at 5:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.