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".
@author Jonathan Locke @author Eelco Hillenius @author Igor Vaynberg (ivaynberg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|