wicket
Class RequestCycle

java.lang.Object
  extended bywicket.RequestCycle
Direct Known Subclasses:
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]?component=[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]?component=[pageId.componentPath]&interface=[interface]

For example:

    /[Application]?component=3.signInForm.submit&interface=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

Field Summary
protected  Application application
          The application object.
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.
protected  java.lang.reflect.Method getInterfaceMethod(java.lang.String interfaceName)
          Looks up an interface method by name.
protected  Page getInvokePage()
          Gets the page that was used for invoking and interface.
 boolean getRedirect()
          Gets whether the page for this request should be redirected.
 Request getRequest()
          Gets the request.
 Response getResponse()
          Gets the response.
 Page getResponsePage()
          Gets the current page.
 Session getSession()
          Gets the session.
protected  void internalOnBeginRequest()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
protected  void internalOnEndRequest()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
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
protected  void onRuntimeException(Page page, java.lang.RuntimeException e)
          Sets up to handle a runtime exception thrown during rendering
protected abstract  boolean parseRequest()
          Parses a request when this request cycle is asked to respond.
protected abstract  void redirectTo(Page page)
          Redirects browser to the given page.
static void registerRequestListenerInterface(java.lang.Class i)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 void request()
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
protected  void setInvokePage(Page page)
           
 void setRedirect(boolean redirect)
          Sets whether the page for this request should be redirected.
 void setRequest(Request request)
           
 void setResponse(Response response)
          Sets response.
 void setResponsePage(Page page)
          Convenience method that sets page on response object.
 void setUpdateCluster(boolean updateCluster)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 java.lang.String toString()
           
 
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.


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

registerRequestListenerInterface

public static void registerRequestListenerInterface(java.lang.Class i)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.

Adds an interface to the map of interfaces that can be invoked by outsiders. The interface must have a single method with the signature methodName(RequestCycle).

Parameters:
i - The interface class, which must extend IRequestListener.

getApplication

public final Application getApplication()
Gets the application object.

Returns:
Application interface

getRedirect

public final 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

getResponse

public final Response getResponse()
Gets the response.

Returns:
Response object

getResponsePage

public final Page getResponsePage()
Gets the current page.

Returns:
The page

getInvokePage

protected final Page getInvokePage()
Gets the page that was used for invoking and interface.

Returns:
The page

getSession

public final Session getSession()
Gets the session.

Returns:
Session object

request

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

Responds to a request.

Throws:
javax.servlet.ServletException

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.

setResponse

public final void setResponse(Response response)
Sets response.

Parameters:
response - The response

setResponsePage

public final void setResponsePage(Page page)
Convenience method that sets page on response object.

Parameters:
page - The page to render as a response

setInvokePage

protected final void setInvokePage(Page page)

setUpdateCluster

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

Parameters:
updateCluster - The updateCluster to set.

getInterfaceMethod

protected final java.lang.reflect.Method getInterfaceMethod(java.lang.String interfaceName)
Looks up an interface method by name.

Parameters:
interfaceName - The interface name
Returns:
The method
Throws:
WicketRuntimeException

internalOnBeginRequest

protected final void internalOnBeginRequest()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL OR OVERRIDE THIS METHOD. Called when the request cycle object is beginning its response


internalOnEndRequest

protected final void internalOnEndRequest()
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL OR OVERRIDE THIS METHOD. Called when the request cycle object has finished its response


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


parseRequest

protected abstract boolean parseRequest()
Parses a request when this request cycle is asked to respond.

Returns:
True if a Page should be rendered back to the user

redirectTo

protected abstract void redirectTo(Page page)
                            throws javax.servlet.ServletException
Redirects browser to the given page. NOTE: Usually, you should never call this method directly, but work with setResponsePage instead. This method is part of Wicket's internal behaviour and should only be used when you want to circumvent the normal framework behaviour and issue the redirect directly.

Parameters:
page - The page to redirect to
Throws:
javax.servlet.ServletException

onRuntimeException

protected final void onRuntimeException(Page page,
                                        java.lang.RuntimeException e)
                                 throws javax.servlet.ServletException
Sets up to handle a runtime exception thrown during rendering

Parameters:
page - Any page context where the exception was thrown
e - The exception
Throws:
javax.servlet.ServletException - The exception rethrown for the servlet container

toString

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


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