org.apache.wicket.request.cycle
Class RequestCycle

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

public class RequestCycle
extends RequestHandlerStack
implements IRequestCycle

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:
RequestHandlerStack.executeRequestHandler(IRequestHandler), RequestHandlerStack.scheduleRequestHandlerAfterCurrent(IRequestHandler), RequestHandlerStack.replaceAllRequestHandlers(IRequestHandler)

Nested Class Summary
static interface RequestCycle.DetachCallback
          Custom callback invoked on request cycle detach.
 
Nested classes/interfaces inherited from class org.apache.wicket.request.RequestHandlerStack
RequestHandlerStack.ReplaceHandlerException
 
Constructor Summary
RequestCycle(RequestCycleContext context)
          Construct.
 
Method Summary
 void detach()
          Detaches all IRequestHandlers.
static RequestCycle get()
          Returns request cycle associated with current thread.
 ClientInfo getClientInfo()
           
protected  int getExceptionRetryCount()
           
<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()
           
protected  RequestCycle getRequestCycle()
           
 long getStartTime()
           
 UrlRenderer getUrlRenderer()
          Returns UrlRenderer for this RequestCycle.
protected  IRequestHandler handleException(java.lang.Exception e)
          Return IRequestHandler for the given exception.
 boolean isCleanupFeedbackMessagesOnDetach()
           
 ClientInfo newClientInfo()
          Creates a new agent info object based on this request.
protected  UrlRenderer newUrlRenderer()
           
 boolean processRequest()
          Processes the request.
 boolean processRequestAndDetach()
          Convenience method that processes the request and detaches the RequestCycle.
 void register(RequestCycle.DetachCallback detachCallback)
          Registers a callback to be invoked on RequestCycle detach.
 java.lang.String renderUrlFor(IRequestHandler handler)
          Returns the rendered URL for the request handler or null if the handler couldn't have been rendered.
protected  IRequestHandler resolveRequestHandler()
          Resolves current request to a IRequestHandler.
 void setCleanupFeedbackMessagesOnDetach(boolean cleanupFeedbackMessagesOnDetach)
           
<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.
 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.
 Url urlFor(IRequestHandler handler)
          Returns URL for the request handler or null if the handler couldn't have been encoded.
 Url urlFor(ResourceReference reference)
          Returns a Url for the resource reference
 Url urlFor(ResourceReference reference, PageParameters params)
          Returns a Url for the resource reference
 
Methods inherited from class org.apache.wicket.request.RequestHandlerStack
executeRequestHandler, getActiveRequestHandler, getRequestHandlerScheduledAfterCurrent, getResponse, replaceAllRequestHandlers, replaceCurrentRequestHandler, scheduleRequestHandlerAfterCurrent, setResponse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.wicket.request.IRequestCycle
getResponse, scheduleRequestHandlerAfterCurrent
 

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 -

getRequestCycle

protected RequestCycle getRequestCycle()
Specified by:
getRequestCycle in class RequestHandlerStack
See Also:
RequestHandlerStack.getRequestCycle()

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

urlFor

public Url urlFor(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

urlFor

public Url urlFor(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

urlFor

public Url urlFor(ResourceReference reference)
Returns a Url for the resource reference

Parameters:
reference - reference
Returns:
Url for the reference

renderUrlFor

public java.lang.String renderUrlFor(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 void detach()
Description copied from class: RequestHandlerStack
Detaches all IRequestHandlers.

Overrides:
detach in class RequestHandlerStack
See Also:
RequestHandlerStack.detach()

register

public void register(RequestCycle.DetachCallback detachCallback)
Registers a callback to be invoked on RequestCycle detach. The callback will be invoked after all IRequestHandlers are detached.

Parameters:
detachCallback -

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 -

newClientInfo

public ClientInfo newClientInfo()
Creates a new agent info object based on this request. Typically, this method is called once by the session and the returned object will be cached in the session after that call; we can expect the client to stay the same for the whole session, and implementations of newClientInfo() might be relatively expensive.

Returns:
the agent info object based on this request

getClientInfo

public ClientInfo getClientInfo()

isCleanupFeedbackMessagesOnDetach

public boolean isCleanupFeedbackMessagesOnDetach()

setCleanupFeedbackMessagesOnDetach

public void setCleanupFeedbackMessagesOnDetach(boolean cleanupFeedbackMessagesOnDetach)

getStartTime

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


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.