...
This dichotomy between component event requests and render requests alleviates a number of problems in traditional web applications related to the browser back button, or to the user hitting the refresh button in their browser.
Contents
Table of Contents | ||
---|---|---|
|
Logical Page Name Shortening
In certain cases, Tapestry will shorten the the logical name of a page. For example, the page class org.example.pages.address.CreateAddress will be given a logical name of "address/Create" (the redundant "Address" is removed as a suffix). However, this only affects how the page is referenced in URLs; the template file will still be CreateAddress.tml, whether on the classpath, or as address/CreateAddress.tml (in the web context).
...
Component Event Requests & Responses
Main Article: Component Events
Component event requests may take the form of hyperlinks (EventLink or ActionLink) or form submissions (Form).
...
The URL for a component event request identifies the name of the page, the nested id of the component, and the name of the event to trigger on the component (this is usually specified by the "event" parameter of EventLink, or "action" for an ActionLink). Further, a component event request may contain additional context information, which will be provided to the event handler method.
...
An event handler method may return a an instance of HttpError instance to send an error response to the client.
...
An event handler can also return a StreamResponse object, which encapsulates a stream to be sent directly to the client browser. This is useful for components that want to, say, generate an image or PDF and provide it to the client.to, say, generate an image or PDF and provide it to the client:
Code Block |
---|
public Object onAction(){
return new StreamResponse() {
@Override
public String getContentType() {
return "application/pdf";
}
@Override
public InputStream getStream() throws IOException {
return new ByteArrayInputStream(getMyPdfByteArray());
}
@Override
public void prepareResponse(Response response) {
response.setHeader("Content-Disposition", "attachment; filename=\"" + myFileName + "\"");
}
};
} |
8. URL response
A java.net.URL response is handled as a client redirect to an external URL. (In Tapestry 5.3.x and earlier this only works for non-Ajax requests.)
...
When a page has an activation context, the values of the context are appended to the URL path. For example, in http://www.example.com/myapp/foo/bar
the "myapp" part is the servlet context (usually the name of your app), and the "foo/bar" part is the activation context, with "foo" being the first activation parameter and "bar" being the second.
...
Info |
---|
Note: If you are using the tapestry-hibernate integration library and your passivate context is a Hibernate entity, then you can just use the entity itself, not its id. Tapestry will automatically extract the entity's id into the URL, and convert it back for the "activate" event handler method. |
Page
...
Activation
When a page render request arrives, the page is activated before it is rendered.
Wiki Markup |
---|
{float:right|background=#eee|padding=0 1em}
*JumpStart Demos:*
[onActivate and onPassivate| |
...
https://tapestry-jumpstart. |
...
org/jumpstart/examples/navigation/onactivateandonpassivate/3] [Handling A Bad Context| |
...
https://tapestry-jumpstart. |
...
org/jumpstart/examples/infrastructure/handlingabadcontext/1] {float} |
Activation serves two purposes:
...
Page activation uses Tapestry's Component Event mechanism. See See Component Events for details.
...
You sometimes need to handle multiple page activation scenarios in one page class. You could create multiple activate event handler methods with different arguments (see the "Multiple Method Matches" section at at Component Events for details), but if you do so, you should generally return true
from each to avoid having more than one activation event handler method from being called for each page request. However, a better approach is to create one method with an EventContext argument. Tapestry will populate the EventContext argument with all of the activation parameters, and the EventContext's get
method will retrieve and coerce each parameter to the desired type. For example:
...
At some point, persistent values make more sense. Tapestry has several persistence strategies available, including one that stores data in URL query parameters. See See Persistent Page Data for details.
Scrollbar |
---|