...
Any individual request will be targeted at a single page. Requests come in two forms:
- component event requests target a specific component on a specific page, triggering an event within that component
- render requests target a specific page, and stream the HTML markup for that page back to the client
...
An event handler method may return a HttpError instance to send an error response to the client.
Code Block |
public Object onAction(){
return new HttpError(302, "The Error message);
} |
...
This querying takes the form of an event trigger. The event name is "passivate" (as we'll see shortly, there's a corresponding "activate"). The return value of the method is used as the context. For example:
Code Block |
|
public class ProductDetail
{
private Product product;
. . .
long onPassivate() { return product.getId(); }
}
|
...
A page's activate event handler mirrors its passivate handler:
Code Block |
|
. . .
void onActivate(long productId)
{
product = productDAO.getById(productId);
}
. . .
|
...
Code Block |
|
java |
title |
ProductListing.html |
|
<t:loop source="products" value="product">
<a t:type="actionlink" t:id="select" context="product.id">${product.name}</a>
</t:loop>
|
Code Block |
|
java |
title |
ProductListing.java |
|
@InjectPage
private ProductDetails details;
Object onActionFromSelect(long productId)
{
details.setProductId(productId);
return details;
}
|
Code Block |
|
java |
title |
ProductDetails.java |
|
@Inject
private ProductDAO dao;
private Product product;
@Persist
private long productId;
public void setProductId(long productId) { this.productId = productId; }
void onActivate()
{
product = dao.getById(productId);
}
|
...
Code Block |
|
java |
title |
ProductDetails.java |
|
@Inject
private ProductDAO dao;
private Product product;
private long productId;
public void setProductId(long productId) { productId = productId; }
void onActivate(long productId)
{
this.productId = productId;
product = dao.getById(productId);
}
long onPassivate() { return productId; }
|
...
Code Block |
|
java |
title |
ProductListing.html |
|
<t:loop source="products" value="product">
<a t:type="pagelink" page="productdetails" context="product.id">${product.name}</a>
</t:loop>
|
Code Block |
|
java |
title |
ProductListing.java |
|
No code is needed to support the link.
|
Code Block |
|
java |
title |
ProductDetails.java |
|
@Inject
private ProductDAO dao;
private Product product;
private long productId;
void onActivate(long productId)
{
this.productId = productId;
product = dao.getById(productId);
}
long onPassivate() { return productId; }
|
...