How to redirect to another page while keeping the original url?

1.1k views Asked by At

In my Wicket 1.5 web application, I want to redirect to another bookmarkable page, whilst the URL of the originating page should remain.

@MountPath(value="page1")
public class WebPage1 extends WebPage {

    public WebPage1() {
        ...
        if (!isDisplayable()) {
            setResponsePage(WebPage2.class);
            // throw new RestartResponseException(Error404WebPage.class);
            // throw new RestartResponseAtInterceptPageException(Error404WebPage.class);
        }
    }

    private boolean isDisplayable() {
        boolean flag = ...
        ...
        return flag;
    }
}

@MountPath(value="page2")
public class WebPage2 extends WebPage {

    public WebPage2() {
    }

    public WebPage2(PageParameters params) {
    }
}

Neither of the approaches with setResponsePage(..), throw new RestartResponseException(..) or throw new RestartResponseAtInterceptPageException(..) leaves the URL unchanged. All three methods redirect to Page2 and change the displayed URL in the browser's address bar.

1

There are 1 answers

0
RJo On

You should supply the RestartResponseException with RedirectPolicy.NEVER_REDIRECT. I.e.

throw new RestartResponseException(new PageProvider(Error404Page.class), RedirectPolicy.NEVER_REDIRECT);