|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.wicket.RequestCycle
public abstract class RequestCycle
Represents the processing of a request. It is responsible for instructing the
request cycle processor
to execute the various steps there are in
the handling of a request (resolving the kind of work that needs to be done, handling of events
and generating a response), and it holds the intended request target
,
which is an abstraction for e.g. the processing of a bookmarkable page.
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:
Bookmarkable pages must either implement a constructor that takes a PageParameters argument or a default constructor. If a Page has both constructors the constructor 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:
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:
For example:
|
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".
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. |
Constructor Summary | |
---|---|
protected |
RequestCycle(Application application,
Request request,
Response response)
Constructor. |
Method Summary | ||
---|---|---|
void |
detach()
Clean up the request cycle. |
|
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. |
|
|
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. |
|
PageParameters |
getPageParameters()
Any set page parameters. |
|
abstract IRequestCycleProcessor |
getProcessor()
Gets the processor for delegated request cycle handling. |
|
boolean |
getRedirect()
Deprecated. Use isRedirect() instead |
|
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 . |
|
Class<? extends Page> |
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()
|
|
boolean |
isRedirect()
Gets whether the page for this request should be redirected. |
|
boolean |
isUrlForNewWindowEncoding()
|
|
protected void |
logRuntimeException(RuntimeException e)
Called when an unrecoverable runtime exception during request cycle handling occurred, which will result in displaying a user facing error page. |
|
protected abstract ClientInfo |
newClientInfo()
Creates a new agent info object based on this request. |
|
protected void |
onAfterTargetsDetached()
Called when the request cycle object has detached all request targets. |
|
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 |
onExceptionLoop(RuntimeException e)
Called when we catch a RuntimeException while already handling another |
|
protected void |
onRequestTargetSet(IRequestTarget requestTarget)
Called when a request target is set on the request cycle |
|
Page |
onRuntimeException(Page page,
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. |
|
protected static void |
set(RequestCycle cycle)
Sets the request cycle for the calling thread. |
|
void |
setAutomaticallyClearFeedbackMessages(boolean automaticallyClearFeedbackMessages)
Permit clients like testers to examine feedback messages after processing. |
|
|
setMetaData(MetaDataKey<T> key,
T object)
Sets the metadata for this request cycle using the given key. |
|
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. |
|
|
setResponsePage(Class<C> pageClass)
Convenience method that sets page class as the response. |
|
|
setResponsePage(Class<C> pageClass,
PageParameters pageParameters)
Sets the page class with optionally the page parameters as the render target of this request. |
|
|
setResponsePage(Class<C> pageClass,
PageParameters pageParameters,
String pageMapName)
Sets the page class with optionally the page parameters and page map name as the render target of this request. |
|
void |
setResponsePage(Page page)
Sets the page as the render target of this request. |
|
void |
setUrlForNewWindowEncoding()
Indicate if the next to be encoded url is targeting a new window (ModalWindow, Pop-up, tab). |
|
String |
toString()
|
|
|
urlFor(Class<C> pageClass,
PageParameters parameters)
Returns a bookmarkable URL that references a given page class using a given set of page parameters. |
|
CharSequence |
urlFor(Component component,
IBehavior behaviour,
RequestListenerInterface listener)
Returns a URL that references a given interface on a given behavior of a component. |
|
CharSequence |
urlFor(Component component,
RequestListenerInterface listener)
Returns a URL that references a given interface on a component. |
|
CharSequence |
urlFor(Component component,
RequestListenerInterface listener,
ValueMap params)
Returns a URL that references a given interface on a component. |
|
|
urlFor(IPageMap pageMap,
Class<C> pageClass,
PageParameters parameters)
Returns a bookmarkable URL that references a given page class using a given set of page parameters. |
|
CharSequence |
urlFor(IRequestTarget requestTarget)
Returns a URL that references the given request target. |
|
CharSequence |
urlFor(Page page)
Returns a URL that references the given page. |
|
CharSequence |
urlFor(PageReference id)
Returns a URL that references the page pointed to by id |
|
CharSequence |
urlFor(ResourceReference resourceReference)
Returns a URL that references a shared resource through the provided resource reference. |
|
CharSequence |
urlFor(ResourceReference resourceReference,
ValueMap parameters)
Returns a URL that references a shared resource through the provided resource reference. |
|
boolean |
wasHandled()
INTERNAL. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected final Application application
protected final IRequestCycleProcessor processor
protected Request request
protected Response response
Constructor Detail |
---|
protected RequestCycle(Application application, Request request, Response response)
application
- The applicationrequest
- The requestresponse
- The responseMethod Detail |
---|
public static RequestCycle get()
protected static void set(RequestCycle cycle)
cycle
- The request cycle to set currentpublic final Application getApplication()
public final ClientInfo getClientInfo()
Session.getClientInfo()
, which may or may not cache the client info object and
typically calls newClientInfo()
when no client info object was cached.
public final Response getOriginalResponse()
public final PageParameters getPageParameters()
Page.Page(PageParameters)
constructor was made.
public abstract IRequestCycleProcessor getProcessor()
@Deprecated public final boolean getRedirect()
isRedirect()
instead
public final Request getRequest()
public final IRequestTarget getRequestTarget()
public final Response getResponse()
public final Page getResponsePage()
PageRequestTarget
.
public final Class<? extends Page> getResponsePageClass()
BookmarkablePageRequestTarget
.
public final Session getSession()
public final long getStartTime()
public boolean isRedirect()
public Page onRuntimeException(Page page, RuntimeException e)
AbstractRequestCycleProcessor.respond(RuntimeException, RequestCycle)
.
page
- Any page context where the exception was throwne
- The exception
public abstract void redirectTo(Page page)
Redirects browser to the given page. Don't use this method directly, but use
setResponsePage(Page)
instead.
page
- The page to redirect topublic final void request()
Responds to a request.
public final void request(Component component)
Responds to a request to re-render a single component.
NOTE: This method is typically only used for testing purposes.
component
- to be re-renderedpublic final void request(IRequestTarget target)
Responds to a request with the request target.
target
- request targetpublic void setAutomaticallyClearFeedbackMessages(boolean automaticallyClearFeedbackMessages)
automaticallyClearFeedbackMessages
- True to automatically detach request cycle at end of processingpublic final void setRedirect(boolean redirect)
redirect
- True if the page for this request cycle should be redirected to rather than
directly rendered.public final void setRequest(Request request)
request
- The request to set.public final void setRequestTarget(IRequestTarget requestTarget)
requestTarget
- the request target to set as currentpublic final Response setResponse(Response response)
response
- The response
public final <C extends Page> void setResponsePage(Class<C> pageClass)
C
- pageClass
- The page class to render as a responsepublic final <C extends Page> void setResponsePage(Class<C> pageClass, PageParameters pageParameters)
C
- pageClass
- The page class to render as a responsepageParameters
- The page parameters that gets appended to the bookmarkable url,public final <C extends Page> void setResponsePage(Class<C> pageClass, PageParameters pageParameters, String pageMapName)
C
- pageClass
- The page class to render as a responsepageParameters
- The page parameters that gets appended to the bookmarkable url,pageMapName
- The Pagemap in which the response page should be createdpublic final void setResponsePage(Page page)
page
- The page to render as a responsepublic String toString()
toString
in class Object
Object.toString()
public final boolean isUrlForNewWindowEncoding()
public final void setUrlForNewWindowEncoding()
public final <C extends Page> CharSequence urlFor(Class<C> pageClass, PageParameters parameters)
C
- pageClass
- Class of pageparameters
- Parameters to page
public final CharSequence urlFor(Component component, IBehavior behaviour, RequestListenerInterface listener)
component
- The component to referencebehaviour
- The behavior to referencelistener
- The listener interface on the component
public final CharSequence urlFor(Component component, RequestListenerInterface listener, ValueMap params)
component
- The component to referencelistener
- The listener interface on the componentparams
- Additional parameters to pass to the page
public final CharSequence urlFor(Component component, RequestListenerInterface listener)
component
- The component to referencelistener
- The listener interface on the component
public final <C extends Page> CharSequence urlFor(IPageMap pageMap, Class<C> pageClass, PageParameters parameters)
C
- pageMap
- Pagemap to use. If null is passed the default page map will be usedpageClass
- Class of pageparameters
- Parameters to page
public final CharSequence urlFor(IRequestTarget requestTarget)
requestTarget
- the request target to reference
public final CharSequence urlFor(Page page)
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.
page
- The page
public final CharSequence urlFor(PageReference id)
id
id
- page id
for more details
public final CharSequence urlFor(ResourceReference resourceReference)
resourceReference
- The resource reference where a url must be generated for.
public final CharSequence urlFor(ResourceReference resourceReference, ValueMap parameters)
resourceReference
- The resource reference where a url must be generated for.parameters
- The parameters to pass to the resource.
public void detach()
protected void onExceptionLoop(RuntimeException e)
RuntimeException
while already handling another
public boolean wasHandled()
protected void logRuntimeException(RuntimeException e)
page expired
exceptions
.
e
- the runtime exceptionprotected abstract ClientInfo newClientInfo()
newClientInfo()
might be relatively expensive.
protected void onBeginRequest()
protected void onAfterTargetsDetached()
protected void onEndRequest()
protected void onRequestTargetSet(IRequestTarget requestTarget)
requestTarget
- public final <T> void setMetaData(MetaDataKey<T> key, T object)
MetaDataKey
.
T
- key
- The singleton key for the metadataobject
- The metadata object
IllegalArgumentException
MetaDataKey
public final <T> T getMetaData(MetaDataKey<T> key)
T
- The type of the metadatakey
- The key for the data
MetaDataKey
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |