Skip to end of metadata
Go to start of metadata

RequestCycle class has been reworked for Wicket 1.5.

General

Now it is better suited for composition by using org.apache.wicket.request.cycle.IRequestCycleListener so it can be extended by several independent libraries. In Wicket 1.4 the user application had to extend (Web)RequestCycle to use the hooks and this made it hard for third party libraries because they don't know about the other and both can extend only WebRequestCycle. Now libraries should register their own IRequestCycleListener (or better AbstractRequestCycleListener) through org.apache.wicket.Application.getRequestCycleListeners().add(listener).

Configuring custom RequestCycle

Extending of the new RequestCycle is still possible. To register custom RequestCycle you have to use org.apache.wicket.Application.setRequestCycleProvider(IRequestCycleProvider).

Tracking requested and response pages

The new RequestCycle implementation doesn't provide methods for getting the page for the current request but this information can be easily tracked with a IRequestCycleListener. Wicket itself uses org.apache.wicket.protocol.http.RequestLoggerRequestCycleListener to track the requested page and the response page for a request. You may use it as inspiration if it doesn't fit your needs as it is.
When doing so you should keep in mind to check IPageRequestHandler.isPageInstanceCreated() before calling IPageRequestHandler.getPage(), because otherwise if for example the constructor of the page threw an exception the getPage can try to instantiate it again and will probably throw an exception again.

This has been simplified even further in Wicket 1.5.8. There is a ready made implementation in the form of org.apache.wicket.request.cycle.PageRequestHandlerTracker. By default, PageRequestHandlerTracker is not registered, so you need to register it explicitly in your application's init() method.

You can get the current response page like this:

Exception handling

Whenever an exception occurs org.apache.wicket.request.cycle.IRequestCycleListener.onException(RequestCycle, Exception) will be called for all registered IRequestCycleListeners. The first one that knows how to handle this kind of exception can return IRequestHandler implementation that will be used to proceed the processing of the request. If none of the IRequestCycleListeners can handle it (i.e. all of them return null) then Wicket will use the configured org.apache.wicket.request.IExceptionMapper. The default one will show the configured error pages (internal error, page expired, access denied, etc.).

Labels