wicket
Class RequestCycle

java.lang.Object
  extended by wicket.RequestCycle
Direct Known Subclasses:
PortletRequestCycle, WebRequestCycle

public abstract class RequestCycle
extends java.lang.Object

THIS CLASS IS DELIBERATELY NOT INSTANTIABLE BY FRAMEWORK CLIENTS AND IS NOT INTENDED TO BE SUBCLASSED BY FRAMEWORK CLIENTS.

Represents the request cycle, including the applicable application, page, request, response and session.

Convenient container for an application, session, request and response object for a page request cycle. Each of these properties can be retrieved with the corresponding getter method. In addition, getPage and setPage can be used to access the page property of the RequestCycle, which determines what page is rendered back to the requester. The setRedirect() method determines if the page should be rendered directly back to the browser or if the browser should instead be redirected to the page (which then renders itself). The actual rendering of the cycle's page is an implementation detail and occurs when the render() method of RequestCycle is called by the framework. The render() method is only public to allow invocation from implementation packages and should never be called directly by clients of the framework.

The abstract urlFor() methods are implemented by subclasses of RequestCycle and return encoded page URLs. The URL returned depends on the kind of page being linked to. Pages broadly fall into two categories:

1. A page that does not yet exist in a user Session may be encoded as a URL that references the not-yet-created page by class name. A set of PageParameters can also be encoded into the URL, and these parameters will be passed to the page constructor if the page later needs to be instantiated.

Any page of this type is bookmarkable, and a hint to that effect is given to the user in the URL:

    /[Application]?bookmarkablePage=[classname]&[param]=[value] [...]

Bookmarkable pages must either implement a constructor that takes a PageParameters argument or a default constructor. If a Page has both constructors the constuctor with the PageParameters argument will be used. Links to bookmarkable pages are created by calling the urlFor(Class, PageParameters) method, where Class is the page class and PageParameters are the parameters to encode into the URL.

2. Stateful pages (that have already been requested by a user) will be present in the user's Session and can be referenced securely with a session-relative number:

    /[Application]?wicket:interface=[pageMapName]:[pageId]: ...

Often, the reason to access an existing session page is due to some kind of "postback" (either a link click or a form submit) from a page (possibly accessed with the browser's back button or possibly not). A call to a registered listener is dispatched like so:

    /[Application]?wicket:interface=[pageMapName]:[pageId]:[componentPath]:[version]:[interfaceName]

For example:

    /[Application]?wicket:interface=:3:signInForm:submit::IFormSubmitListener

URLs for stateful pages (those that already exist in the session map) are created by calling the urlFor(Component, Class) method, where Component is the component being linked to and Class is the interface on the component to call.

For pages falling into the second category, listener interfaces cannot be invoked unless they have first been registered via the static registerSecureInterface() method. This method ensures basic security by restricting the set of interfaces that outsiders can call via GET and POST requests. Each listener interface has a single method which takes only a RequestCycle parameter. Currently, the following classes register the following kinds of listener interfaces:

Class Interface Purpose
Form IFormSubmitListener Handle form submits
Image IResourceListener Respond to image resource requests
Link ILinkListener Respond to link clicks
Page IRedirectListener Respond to redirects

The redirectToInterceptPage() and continueToOriginalDestination() methods can be used to temporarily redirect a user to some page. This is mainly intended for use in signing in users who have bookmarked a page inside a site that requires the user be authenticated before they can access the page. When it is discovered that the user is not signed in, the user is redirected to the sign-in page with redirectToInterceptPage(). When the user has signed in, they are sent on their way with continueToOriginalDestination(). These methods could also be useful in "interstitial" advertising or other kinds of "intercepts".

Author:
Jonathan Locke, Eelco Hillenius, Igor Vaynberg (ivaynberg)

Field Summary
protected  Application application
          The application object.
protected  IRequestCycleProcessor processor
          The processor for this request.
protected  Request request
          The current request.
protected  Response response
          The current response.
protected  Session session
          The session object.
 
Constructor Summary
protected RequestCycle(Session session, Request request, Response response)
          Constructor.
 
Method Summary
static RequestCycle get()
          Gets request cycle for calling thread.
 Application getApplication()
          Gets the application object.
 ClientInfo getClientInfo()
          Gets the new agent info object for this session.
 Response getOriginalResponse()
          Get the orignal respone the request was create with.
abstract  IRequestCycleProcessor getProcessor()
          Gets the processor for delegated request cycle handling.
 boolean getRedirect()
          Gets whether the page for this request should be redirected.
 Request getRequest()
          Gets the request.
 IRequestTarget getRequestTarget()
          Gets the current request target.
 Response getResponse()
          Gets the response.
 Page getResponsePage()
          Gets the page that is to be rendered for this request in case the last set request target is of type PageRequestTarget.
 java.lang.Class getResponsePageClass()
          Gets the page class that is to be instantiated and rendered for this request in case the last set request target is of type BookmarkablePageRequestTarget.
 Session getSession()
          Gets the session.
 long getStartTime()
           
protected abstract  ClientInfo newClientInfo()
          Creates a new agent info object based on this request.
protected  void onBeginRequest()
          Called when the request cycle object is beginning its response
protected  void onEndRequest()
          Called when the request cycle object has finished its response
 Page onRuntimeException(Page page, java.lang.RuntimeException e)
          Template method that is called when a runtime exception is thrown, just before the actual handling of the runtime exception.
abstract  void redirectTo(Page page)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void request()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void request(Component component)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void request(IRequestTarget target)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void setRedirect(boolean redirect)
          Sets whether the page for this request should be redirected.
 void setRequest(Request request)
           
 void setRequestTarget(IRequestTarget requestTarget)
          Sets the request target as the current.
 Response setResponse(Response response)
          Sets response.
 void setResponsePage(java.lang.Class pageClass)
          Convenience method that sets page class as the response.
 void setResponsePage(java.lang.Class pageClass, PageParameters pageParameters)
          Sets the page class with optionally the page parameters as the render target of this request.
 void setResponsePage(Page page)
          Sets the page as the render target of this request.
 void setUpdateSession(boolean updateCluster)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 java.lang.String toString()
           
 java.lang.CharSequence urlFor(Component component, RequestListenerInterface listener)
          Returns a URL that references a given interface on a component.
 java.lang.CharSequence urlFor(IRequestTarget requestTarget)
          Returns a URL that references the given request target.
 java.lang.CharSequence urlFor(Page page)
          Returns a URL that references the given page.
 java.lang.CharSequence urlFor(PageMap pageMap, java.lang.Class pageClass, PageParameters parameters)
          Returns a bookmarkable URL that references a given page class using a given set of page parameters.
 java.lang.CharSequence urlFor(ResourceReference resourceReference)
          Returns a URL that references a shared resource through the provided resource reference.
 java.lang.CharSequence urlFor(ResourceReference resourceReference, ValueMap parameters)
          Returns a URL that references a shared resource through the provided resource reference.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

application

protected final Application application
The application object.


processor

protected final IRequestCycleProcessor processor
The processor for this request.


request

protected Request request
The current request.


response

protected Response response
The current response.


session

protected final Session session
The session object.

Constructor Detail

RequestCycle

protected RequestCycle(Session session,
                       Request request,
                       Response response)
Constructor.

Parameters:
session - The session
request - The request
response - The response
Method Detail

get

public static final RequestCycle get()
Gets request cycle for calling thread.

Returns:
Request cycle for calling thread

getApplication

public final Application getApplication()
Gets the application object.

Returns:
Application interface

getClientInfo

public final ClientInfo getClientInfo()
Gets the new agent info object for this session. This method calls Session.getClientInfo(), which may or may not cache the client info object and typically calls newClientInfo() when no client info object was cached.

Returns:
the agent info object based on this request

getOriginalResponse

public final Response getOriginalResponse()
Get the orignal respone the request was create with. Access may be necessary with the response has temporarily being replaced but your components requires access to lets say the cookie methods of a WebResponse.

Returns:
The original response object.

getProcessor

public abstract IRequestCycleProcessor getProcessor()
Gets the processor for delegated request cycle handling.

Returns:
the processor for delegated request cycle handling

getRedirect

public boolean getRedirect()
Gets whether the page for this request should be redirected.

Returns:
whether the page for this request should be redirected

getRequest

public final Request getRequest()
Gets the request.

Returns:
Request object

getRequestTarget

public final IRequestTarget getRequestTarget()
Gets the current request target. May be null.

Returns:
the current request target, null if none was set yet.

getResponse

public final Response getResponse()
Gets the response.

Returns:
Response object

getResponsePage

public final Page getResponsePage()
Gets the page that is to be rendered for this request in case the last set request target is of type PageRequestTarget.

Returns:
the page or null

getResponsePageClass

public final java.lang.Class getResponsePageClass()
Gets the page class that is to be instantiated and rendered for this request in case the last set request target is of type BookmarkablePageRequestTarget.

Returns:
the page class or null

getSession

public final Session getSession()
Gets the session.

Returns:
Session object

getStartTime

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

onRuntimeException

public Page onRuntimeException(Page page,
                               java.lang.RuntimeException e)
Template method that is called when a runtime exception is thrown, just before the actual handling of the runtime exception. This is called by DefaultExceptionResponseStrategy, hence if that strategy is replaced by another one, there is no guarantee this method is called.

Parameters:
page - Any page context where the exception was thrown
e - The exception
Returns:
Any error page to redirect to

redirectTo

public abstract void redirectTo(Page page)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.

Redirects browser to the given page. Don't use this method directly, but use setResponsePage(Page) instead.

Parameters:
page - The page to redirect to

request

public final void request()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.

Responds to a request.


request

public final void request(Component component)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.

Responds to a request to re-render a single component.

NOTE: This method is typically only used for testing purposes.

Parameters:
component - to be re-rendered

request

public final void request(IRequestTarget target)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.

Responds to a request with the request target.

Parameters:
target - request target

setRedirect

public final void setRedirect(boolean redirect)
Sets whether the page for this request should be redirected.

Parameters:
redirect - True if the page for this request cycle should be redirected to rather than directly rendered.

setRequest

public final void setRequest(Request request)
Parameters:
request - The request to set.

setRequestTarget

public final void setRequestTarget(IRequestTarget requestTarget)
Sets the request target as the current.

Parameters:
requestTarget - the request target to set as current

setResponse

public final Response setResponse(Response response)
Sets response.

Parameters:
response - The response
Returns:
the original response

setResponsePage

public final void setResponsePage(java.lang.Class pageClass)
Convenience method that sets page class as the response. This will generate a redirect to the page with a bookmarkable url

Parameters:
pageClass - The page class to render as a response

setResponsePage

public final void setResponsePage(java.lang.Class pageClass,
                                  PageParameters pageParameters)
Sets the page class with optionally the page parameters as the render target of this request.

Parameters:
pageClass - The page class to render as a response
pageParameters - The page parameters that gets appended to the bookmarkable url,

setResponsePage

public final void setResponsePage(Page page)
Sets the page as the render target of this request.

Parameters:
page - The page to render as a response

setUpdateSession

public void setUpdateSession(boolean updateCluster)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT.

Parameters:
updateCluster - The updateCluster to set.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

urlFor

public final java.lang.CharSequence urlFor(Component component,
                                           RequestListenerInterface listener)
Returns a URL that references a given interface on a component. When the URL is requested from the server at a later time, the interface will be called. A URL returned by this method will not be stable across sessions and cannot be bookmarked by a user.

Parameters:
component - The component to reference
listener - The listener interface on the component
Returns:
A URL that encodes a page, component and interface to call

urlFor

public final java.lang.CharSequence urlFor(IRequestTarget requestTarget)
Returns a URL that references the given request target.

Parameters:
requestTarget - the request target to reference
Returns:
a URL that references the given request target

urlFor

public final java.lang.CharSequence urlFor(Page page)
Returns a URL that references the given page. It also touches the page in the session so that it is put in the front of the page stack. Use this method only if you plan to use it the next request.

Parameters:
page - The page
Returns:
The url pointing to the provided page

urlFor

public final java.lang.CharSequence urlFor(PageMap pageMap,
                                           java.lang.Class 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.

Parameters:
pageMap - Pagemap to use
pageClass - Class of page
parameters - Parameters to page
Returns:
Bookmarkable URL to page

urlFor

public final java.lang.CharSequence urlFor(ResourceReference resourceReference)
Returns a URL that references a shared resource through the provided resource reference.

Parameters:
resourceReference - The resource reference where a url must be generated for.
Returns:
The url for the shared resource

urlFor

public final java.lang.CharSequence urlFor(ResourceReference resourceReference,
                                           ValueMap parameters)
Returns a URL that references a shared resource through the provided resource reference.

Parameters:
resourceReference - The resource reference where a url must be generated for.
parameters - The parameters to pass to the resource.
Returns:
The url for the shared resource

newClientInfo

protected abstract 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

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



Copyright © 2004-2007 Wicket developers. All Rights Reserved.