Matteo Pezzanera
Matteo Pezzanera

Reputation: 53

Wicket setResponsePage() inside onBeforeRender()

I have a web application based on Apache Wicket. I have a problem with the usage of the method onBeforRender() of a web page. I need to use this method to intercept the creation of a page, and redirect the user to another page. If I use setResponsePage inside the onBeforeRender, the page is aniway rendered. How Can I implement my desired behavior?

Upvotes: 1

Views: 400

Answers (2)

Friederike
Friederike

Reputation: 1282

I think this should work:

throw new RestartResponseAtInterceptPageException(SomePage.class);

As it is an exception it should prevent any other code(=rendering) from being executed.

I'm not sure why you are redirecting. My guess is that it's an authorization topic. Then you might want to check out the IAuthorizationStrategy. It's described in the official Wicket docu. They have a very good documentation over there with lots of best practises and examples.

Upvotes: 1

martin-g
martin-g

Reputation: 17513

Which org.apache.wicket.settings.RequestCycleSettings.RenderStrategy do you use ? I believe your problem can happen only with org.apache.wicket.settings.RequestCycleSettings.RenderStrategy#ONE_PASS_RENDER.

Try to use #onInitialize() or #onConfigure() instead.

Upvotes: 0

Related Questions