org.apache.wicket.request.cycle
Class RequestCycle

java.lang.Object
  extended by org.apache.wicket.request.cycle.RequestCycle
All Implemented Interfaces:
IEventSink, IRequestCycle
Direct Known Subclasses:
WicketExampleRequestCycle

public class RequestCycle
extends java.lang.Object
implements IRequestCycle, IEventSink

RequestCycle consists of two steps:

  1. Resolve request handler
  2. Execute request handler
During IRequestHandler execution the handler can execute other IRequestHandlers, schedule another IRequestHandler or replace all IRequestHandlers on stack with another IRequestHandler.

Author:
Matej Knopp, igor.vaynberg
See Also:
#execute(IRequestHandler), scheduleRequestHandlerAfterCurrent(IRequestHandler), replaceAllRequestHandlers(IRequestHandler)

Constructor Summary
RequestCycle(RequestCycleContext context)
          Construct.
 
Method Summary
 void detach()
          Detaches RequestCycle state.
static RequestCycle get()
          Returns request cycle associated with current thread.
 IRequestHandler getActiveRequestHandler()
           
protected  int getExceptionRetryCount()
           
 RequestCycleListenerCollection getListeners()
           
<T> T
getMetaData(MetaDataKey<T> key)
          Gets metadata for this request cycle using the given key.
 Response getOriginalResponse()
          Get the original response the request was created with.
 Request getRequest()
           
 IRequestHandler getRequestHandlerScheduledAfterCurrent()
           
 Response getResponse()
          Get the active response at the request cycle.
 long getStartTime()
           
 UrlRenderer getUrlRenderer()
          Returns UrlRenderer for this RequestCycle.
protected  IRequestHandler handleException(java.lang.Exception e)
          Return IRequestHandler for the given exception.
 boolean isCleanupFeedbackMessagesOnDetach()
          Gets whether or not feedback messages are to be cleaned up on detach.
<C extends Page>
Url
mapUrlFor(java.lang.Class<C> pageClass, PageParameters parameters)
          Returns a bookmarkable URL that references a given page class using a given set of page parameters.
 Url mapUrlFor(IRequestHandler handler)
          Returns URL for the request handler or null if the handler couldn't have been encoded.
 Url mapUrlFor(ResourceReference reference, PageParameters params)
          Returns a Url for the resource reference
protected  UrlRenderer newUrlRenderer()
           
protected  void onBeginRequest()
          Called when the request cycle object is beginning its response
 void onDetach()
          Called after request processing is complete, usually takes care of detaching state
protected  void onEndRequest()
          Called when the request cycle object has finished its response
 void onEvent(IEvent<?> event)
          Called when an event is sent to this sink
 boolean processRequest()
          Processes the request.
 boolean processRequestAndDetach()
          Convenience method that processes the request and detaches the RequestCycle.
 void replaceAllRequestHandlers(IRequestHandler handler)
           
protected  IRequestHandler resolveRequestHandler()
          Resolves current request to a IRequestHandler.
 void scheduleRequestHandlerAfterCurrent(IRequestHandler handler)
          Schedule the request handler to be executed after the current one.
 void setCleanupFeedbackMessagesOnDetach(boolean cleanupFeedbackMessagesOnDetach)
          Sets whether or not feedback messages should be cleaned up on detach.
<T> void
setMetaData(MetaDataKey<T> key, T object)
          Sets the metadata for this request cycle using the given key.
 void setRequest(Request request)
          INTERNAL This method is for internal Wicket use.
 Response setResponse(Response response)
          Replaces current Response with new Response instance.
 void setResponsePage(java.lang.Class<? extends IRequestablePage> pageClass)
          Convenience method for setting next page to be rendered.
 void setResponsePage(java.lang.Class<? extends IRequestablePage> pageClass, PageParameters parameters)
          Convenience method for setting next page to be rendered.
 void setResponsePage(IRequestablePage page)
          Convenience method for setting next page to be rendered.
<C extends Page>
java.lang.CharSequence
urlFor(java.lang.Class<C> pageClass, PageParameters parameters)
          Returns a rendered bookmarkable URL that references a given page class using a given set of page parameters.
 java.lang.CharSequence urlFor(IRequestHandler handler)
          Returns the rendered URL for the request handler or null if the handler couldn't have been rendered.
 java.lang.CharSequence urlFor(ResourceReference reference, PageParameters params)
          Returns a rendered Url for the resource reference
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestCycle

public RequestCycle(RequestCycleContext context)
Construct.

Parameters:
context -
Method Detail

get

public static RequestCycle get()
Returns request cycle associated with current thread.

Returns:
request cycle instance or null if no request cycle is associated with current thread.

newUrlRenderer

protected UrlRenderer newUrlRenderer()
Returns:
a new url renderer

getOriginalResponse

public Response getOriginalResponse()
Get the original response the request was created with. Access to the original response may be necessary if the response has been temporarily replaced but the components require methods from original response (i.e. cookie methods of WebResponse, etc).

Returns:
The original response object.

getUrlRenderer

public final UrlRenderer getUrlRenderer()
Returns UrlRenderer for this RequestCycle.

Specified by:
getUrlRenderer in interface IRequestCycle
Returns:
UrlRenderer instance.

resolveRequestHandler

protected IRequestHandler resolveRequestHandler()
Resolves current request to a IRequestHandler.

Returns:
RequestHandler instance

getExceptionRetryCount

protected int getExceptionRetryCount()
Returns:
How many times will Wicket attempt to render the exception request handler before giving up.

processRequest

public boolean processRequest()
Processes the request.

Returns:
true if the request resolved to a Wicket request, false otherwise.

processRequestAndDetach

public boolean processRequestAndDetach()
Convenience method that processes the request and detaches the RequestCycle.

Returns:
true if the request resolved to a Wicket request, false otherwise.

handleException

protected IRequestHandler handleException(java.lang.Exception e)
Return IRequestHandler for the given exception.

Parameters:
e -
Returns:
RequestHandler instance

getRequest

public Request getRequest()
Specified by:
getRequest in interface IRequestCycle
Returns:
current request

setRequest

public void setRequest(Request request)
INTERNAL This method is for internal Wicket use. Do not call it yourself unless you know what you are doing.

Parameters:
request -

setMetaData

public final <T> void setMetaData(MetaDataKey<T> key,
                                  T object)
Sets the metadata for this request cycle using the given key. If the metadata object is not of the correct type for the metadata key, an IllegalArgumentException will be thrown. For information on creating MetaDataKeys, see MetaDataKey.

Type Parameters:
T -
Parameters:
key - The singleton key for the metadata
object - The metadata object
Throws:
java.lang.IllegalArgumentException
See Also:
MetaDataKey

getMetaData

public final <T> T getMetaData(MetaDataKey<T> key)
Gets metadata for this request cycle using the given key.

Type Parameters:
T - The type of the metadata
Parameters:
key - The key for the data
Returns:
The metadata or null if no metadata was found for the given key
See Also:
MetaDataKey

mapUrlFor

public Url mapUrlFor(IRequestHandler handler)
Returns URL for the request handler or null if the handler couldn't have been encoded.

Parameters:
handler -
Returns:
Url instance or null

mapUrlFor

public Url mapUrlFor(ResourceReference reference,
                     PageParameters params)
Returns a Url for the resource reference

Parameters:
reference - resource reference
params - parameters for the resource or null if none
Returns:
Url for the reference

mapUrlFor

public final <C extends Page> Url mapUrlFor(java.lang.Class<C> pageClass,
                                            PageParameters parameters)
Returns a bookmarkable URL that references a given page class using a given set of page parameters. Since the URL which is returned contains all information necessary to instantiate and render the page, it can be stored in a user's browser as a stable bookmark.

Type Parameters:
C -
Parameters:
pageClass - Class of page
parameters - Parameters to page or null if none
Returns:
Bookmarkable URL to page

urlFor

public final java.lang.CharSequence urlFor(ResourceReference reference,
                                           PageParameters params)
Returns a rendered Url for the resource reference

Parameters:
reference - resource reference
params - parameters for the resource or null if none
Returns:
Url for the reference

urlFor

public final <C extends Page> java.lang.CharSequence urlFor(java.lang.Class<C> pageClass,
                                                            PageParameters parameters)
Returns a rendered bookmarkable URL that references a given page class using a given set of page parameters. Since the URL which is returned contains all information necessary to instantiate and render the page, it can be stored in a user's browser as a stable bookmark.

Type Parameters:
C -
Parameters:
pageClass - Class of page
parameters - Parameters to page or null if none
Returns:
Bookmarkable URL to page

urlFor

public java.lang.CharSequence urlFor(IRequestHandler handler)
Returns the rendered URL for the request handler or null if the handler couldn't have been rendered.

The resulting URL will be relative to current page.

Parameters:
handler -
Returns:
Url String or null

detach

public final void detach()
Detaches RequestCycle state. Called after request processing is complete


onDetach

public void onDetach()
Called after request processing is complete, usually takes care of detaching state


setResponsePage

public void setResponsePage(IRequestablePage page)
Convenience method for setting next page to be rendered.

Parameters:
page -

setResponsePage

public void setResponsePage(java.lang.Class<? extends IRequestablePage> pageClass)
Convenience method for setting next page to be rendered.

Parameters:
pageClass -

setResponsePage

public void setResponsePage(java.lang.Class<? extends IRequestablePage> pageClass,
                            PageParameters parameters)
Convenience method for setting next page to be rendered.

Parameters:
pageClass -
parameters -

isCleanupFeedbackMessagesOnDetach

public boolean isCleanupFeedbackMessagesOnDetach()
Gets whether or not feedback messages are to be cleaned up on detach.

Returns:
true if they are

setCleanupFeedbackMessagesOnDetach

public void setCleanupFeedbackMessagesOnDetach(boolean cleanupFeedbackMessagesOnDetach)
Sets whether or not feedback messages should be cleaned up on detach.

Parameters:
cleanupFeedbackMessagesOnDetach - true if you want them to be cleaned up

getStartTime

public final long getStartTime()
Returns:
The start time for this request

onEvent

public void onEvent(IEvent<?> event)
Called when an event is sent to this sink

Specified by:
onEvent in interface IEventSink

onBeginRequest

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


onEndRequest

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


getListeners

public RequestCycleListenerCollection getListeners()
Returns:
listeners

getResponse

public Response getResponse()
Get the active response at the request cycle.

Specified by:
getResponse in interface IRequestCycle
Returns:
response

setResponse

public Response setResponse(Response response)
Replaces current Response with new Response instance. The original response is always restored after the IRequestHandler.respond(IRequestCycle) method is finished.

Specified by:
setResponse in interface IRequestCycle
Returns:
Response being replaced.

scheduleRequestHandlerAfterCurrent

public void scheduleRequestHandlerAfterCurrent(IRequestHandler handler)
Schedule the request handler to be executed after the current one.

Specified by:
scheduleRequestHandlerAfterCurrent in interface IRequestCycle

getActiveRequestHandler

public IRequestHandler getActiveRequestHandler()
Returns:
active handler on executor
See Also:
RequestHandlerStack.getActive()

getRequestHandlerScheduledAfterCurrent

public IRequestHandler getRequestHandlerScheduledAfterCurrent()
Returns:
the handler scheduled to be executed after current by the executor
See Also:
RequestHandlerStack.next()

replaceAllRequestHandlers

public void replaceAllRequestHandlers(IRequestHandler handler)
Parameters:
handler -
See Also:
RequestHandlerStack.replaceAll(IRequestHandler)


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