Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The user will see the newly generated content in their browser. In addition, the URL in the browser's address bar will be a render request URL. Render request URLs are shorter and contain less application structure (for instance, they don't include component ids or event types). Render requests URLs are what your users will bookmark. The component event request URLs are transitory, meaningful only while the application is actively engaged, and not meant to be used in later sessions.

Code Block
public Object onAction(){
  return null;
}

When a string is returned, it is expected to be the logical name of a page (as opposed to the page's fully qualified class name). As elsewhere, the name of the page is case insensitive.

Again, a render request URL will be constructed and sent to the client as a redirect.

Code Block
public String onAction(){
  return "Index";
}

When a class is returned, it is expected to be a page class. Returning a page class from an event handler is safer for refactoring than returning a page name.

As with other response types, a render request URL will be constructed and sent to the client as a redirect.

Code Block
public Object onAction(){
  return Index.class
}

You may also return an instance of a page, rather than the name or class of a page.

...

You can also return a component within the page, but this will generate a runtime warning (unless you are doing a partial-page update via Ajax).
@InjectPage
private Index index;

Code Block
public Object onAction(){
  return index;
}

An event handler method may return a Link instance directly. The Link is converted into a URL and a client redirect to that URL is sent to the client.

...

Code Block
java
java
public class ProductDetail
{
  private Product product;
  
  . . .
  
  long onPassivate() { return product.getId(); }
}

...

A page's activate event handler mirrors its passivate handler:

Code Block
java
java
  . . .
  
  void onActivate(long productId)
  {
     product = productDAO.getById(productId);
  }
  
  . . .

Here's the relevant part: when the page renders, it is likely to include more component event request URLs (links and forms). The component event requests for those links and forms will also start by activating the page, before performing other work. This forms an unbroken chain of requests that include the same activation context.

...

Code Block
java
java
titleProductListing.java
  @InjectPage
  private ProductDetails details;
  
  Object onActionFromSelect(long productId)
  {
    details.setProductId(productId);
    
    return details;
  }
Code Block
java
java
titleProductDetails.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
java
titleProductDetails.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
java
titleProductDetails.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; }

...