Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

RequestCycle has changed in 1.5-M1 and WebRequestCycle has been removed.

When we want to override RequestCycle's methods and write our logic codes we can not do it like 1.4.x.

eg.

In 1.4 you would have overridden onBeginRequest, onEndRequest, and onRuntimeException, like so:

Code Block
titleReqeustCycle
borderStylesolid
public MyRequestCycle extends WebRequestCycle {
    @Override
    public void onBeginRequest() {
      //...
    }
    
    @Override
    public void onEndRequest() {
        //...
    }
    
   @Override         
    public Page onRuntimeException(Page page, RuntimeException e) {
        // ...
    }
}

In 1.5, onRuntimeException is gone (see next section). You can still override onBeginRequest and onEndRequest. However, if you are creating a framework that needs to be able to "plug in" functionality into those callbacks, it is recommended that you no longer create a subclass of RequestCycle that your users must also subclass. This limits them from using two such frameworks. Now there is RequestCycle#IRequestCycleListener that you can plug in, either to the cycle itself or to the application, and you will be notified of all of these method callbacks. For example:

Code Block
titleIRequestCycleListener
borderStylesolid
public class SomeWebApplication extends WebApplication
{

	@Override
	protected void init()
	{
		addRequestCycleListener(new IRequestCycleListener()
		{

			public void onException(Exception ex)
			{
				// do something here whene there's an exception
			}

			public void onEndRequest()
			{
				// do something at the end of the request
			}

			public void onBeginRequest()
			{
				// do something at the beginning of the request
			}
		});
	}

	@Override
	public Class<? extends Page> getHomePage()
	{
		return SomePage.class;
	}
}

Note also that instead of overriding org.apache.wicket.Application.newRequestCycle(...), you will now call org.apache.wicket.Application.setRequestCycleProvider(IRequestCycleProvider) in your Application#init method to provide a factory that can return any custom RequestCycle that you do want to create, although with the plugins, the need to create a custom request cycle is much lower now this case we'll need to extend RequestCycle and Override org.apache.wicket.Application.setRequestCycleProvider(IRequestCycleProvider) to return our a provider for a custom RequestCycle implementation.

Exception handling

In Wicket 1.4 it was needed to extend org.apache.wicket.RequestCycle.onRuntimeException(Page, RuntimeException).
Wicket 1.5 gives even better control, by overriding org.apache.wicket.Application.newExceptionMapper() it is possible to change even the default processing of error pages.

...