How does Wicket setResponsePage() method work?
Asked Answered
U

2

5

When learning about JSP and servlets, I heard about redirect and dispatch. Which of them does Wicket's setResponsePage() perform?

Uveitis answered 10/4, 2012 at 17:29 Comment(0)
E
19

What setResponsePage does is dependent on a couple of factors: how many times you call setResponsePage, which variant of the setResponsePage you call and what render strategy you use.

You can call setResponsePage many times during a request. Wicket uses the last one to work with.

There are two variants of setResponsePage: with a Page instance and with a Page class and PageParameters. The latter sends a redirect to a bookmarkable URL to the browser. The former will, depending on the render strategy, either:

  • ONE_PASS_RENDER
    • render the page directly to the browser
  • REDIRECT_TO_BUFFER
    • render the page to a buffer, send a redirect to the browser (which then retrieves the buffered, rendered markup), or
  • REDIRECT_TO_RENDER
    • send a redirect to the browser, which then sends a request to render the page

So the first option is dispatch, the second option is dispatch followed by a redirect, and the third option would be redirect in servlet terms.

Elbert answered 11/4, 2012 at 6:22 Comment(5)
@Martin Dashorst: does the browser see a 302 in REDIRECT_TO_BUFFER?Yodle
Just tried it with my project: Request URL:localhost:8080/som/app/home?14-2.ILinkListener-menu-personalia Request Method:GET Status Code:302 Found So yes, Wicket sends a 302 in that case.Elbert
@Martin Dashorst: thanks, this actualy explains why we have an 302 that takes longer than the 2, reqeust, because of the buffer. Great, another mystery solved ;)Yodle
Thanks, I can now relax knowing that XD. May be someday be some wicket guru like you or Igor. LoL.Uveitis
The right render strategy to use may vary case by case. The setting is application-wide. Shouldn't it be (ideally) set per request cycle?Tallowy
S
1

setResponsePage(PageName.class) will redirect the browser to the PageName you need to go. Make sure that, you have already mount your Page.class to a given path. For example, in your Application init method, you can mount like this mountPage("/home.html", WelcomePage.class); then in some other page, when you have a need to go to the home page, you just call like this setResponsePage(WelcomePage.class);

Shaikh answered 9/4, 2013 at 16:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.