org.apache.wicket.request.cycle
Interface IRequestCycleListener

All Known Implementing Classes:
AbstractRequestCycleListener, RequestCycleListenerCollection, RequestLoggerRequestCycleListener

public interface IRequestCycleListener

A callback interface for various methods in the request cycle. If you are creating a framework that needs to do something in this methods, rather than extending RequestCycle or one of its subclasses, you should implement this callback and allow users to add your listener to their custom request cycle.

These listeners can be added directly to the request cycle when it is created or to the Application.

NOTE: a listener implementation is a singleton and hence needs to ensure proper handling of multi-threading issues.

Call order

The interface methods are ordered in the execution order as Wicket goes through the request cycle:

  1. onBeginRequest(RequestCycle)
  2. onEndRequest(RequestCycle)
  3. onDetach(RequestCycle)

The previous call sequence is valid for any Wicket request passing through the Wicket filter. Additionally when a request handler was resolved, a new handler scheduled, or an unhandled exception occurred during the request processing, any of the following can be called:

Implementing your own

Use AbstractRequestCycleListener for a default, empty implementation as a base class.

Example

A short example of a request counter.

 public class RequestCounter extends AbstractRequestCycleListener
 {
        private AtomicLong counter = new AtomicLong(0);
 
        public void onBeginRequest(RequestCycle cycle)
        {
                counter.incrementAndGet();
        }
 
        public long getRequestCount()
        {
                return counter.longValue();
        }
 }
 
 public class MyApplication extends WebApplication
 {
        public void init()
        {
                super.init();
                getRequestCycleListeners().add(new RequestCounter());
        }
 }
 

Author:
Jeremy Thomerson, Martijn Dashorst
See Also:
AbstractRequestCycleListener, Application#addRequestCycleListener(IRequestCycleListener)

Method Summary
 void onBeginRequest(RequestCycle cycle)
          Called when the request cycle object is beginning its response
 void onDetach(RequestCycle cycle)
          Called after the request cycle has been detached
 void onEndRequest(RequestCycle cycle)
          Called when the request cycle object has finished its response
 IRequestHandler onException(RequestCycle cycle, java.lang.Exception ex)
          Called when there is an exception in the request cycle that would normally be handled by RequestCycle.handleException(Exception) Note that in the event of an exception, #onEndRequest() will still be called after these listeners have #onException(Exception) called
 void onExceptionRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler, java.lang.Exception exception)
          Called when an IRequestHandler is resolved for an exception and will be executed.
 void onRequestHandlerExecuted(RequestCycle cycle, IRequestHandler handler)
          Called after an IRequestHandler has been executed.
 void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler)
          Called when an IRequestHandler is resolved and will be executed.
 void onRequestHandlerScheduled(RequestCycle cycle, IRequestHandler handler)
          Called when a IRequestHandler has been scheduled.
 void onUrlMapped(RequestCycle cycle, IRequestHandler handler, Url url)
          Called after a Url is generated for a IRequestHandler.
 

Method Detail

onBeginRequest

void onBeginRequest(RequestCycle cycle)
Called when the request cycle object is beginning its response

Parameters:
cycle -

onEndRequest

void onEndRequest(RequestCycle cycle)
Called when the request cycle object has finished its response

Parameters:
cycle -

onDetach

void onDetach(RequestCycle cycle)
Called after the request cycle has been detached

Parameters:
cycle -

onRequestHandlerResolved

void onRequestHandlerResolved(RequestCycle cycle,
                              IRequestHandler handler)
Called when an IRequestHandler is resolved and will be executed.

Parameters:
cycle -
handler -

onRequestHandlerScheduled

void onRequestHandlerScheduled(RequestCycle cycle,
                               IRequestHandler handler)
Called when a IRequestHandler has been scheduled. Can be called multiple times during a request when new handlers get scheduled for processing.

Parameters:
cycle -
handler -
See Also:
RequestCycle.scheduleRequestHandlerAfterCurrent(IRequestHandler)

onException

IRequestHandler onException(RequestCycle cycle,
                            java.lang.Exception ex)
Called when there is an exception in the request cycle that would normally be handled by RequestCycle.handleException(Exception) Note that in the event of an exception, #onEndRequest() will still be called after these listeners have #onException(Exception) called

Parameters:
cycle -
ex - the exception that was passed in to RequestCycle.handleException(Exception)
Returns:
request handler that will be executed or null if none. If a request handler is returned, it will override any configured exception mapper

onExceptionRequestHandlerResolved

void onExceptionRequestHandlerResolved(RequestCycle cycle,
                                       IRequestHandler handler,
                                       java.lang.Exception exception)
Called when an IRequestHandler is resolved for an exception and will be executed.

Parameters:
cycle -
handler -
exception -

onRequestHandlerExecuted

void onRequestHandlerExecuted(RequestCycle cycle,
                              IRequestHandler handler)
Called after an IRequestHandler has been executed. If the execution resulted in an exception this method will not be called for that particular IRequestHandler.

Parameters:
cycle -
handler -

onUrlMapped

void onUrlMapped(RequestCycle cycle,
                 IRequestHandler handler,
                 Url url)
Called after a Url is generated for a IRequestHandler. This method can be used to modify generated urls, for example query parameters can be added.

Parameters:
cycle -
handler -
url -


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.