Versions Compared

Key

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

...

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|http://jumpstart.doublenegative.com.au/jumpstart/examples/navigation/onactivateandonpassivate/3]
    [Handling A Bad Context|http://jumpstart.doublenegative.com.au/jumpstart/examples/infrastructure/handlingabadcontext/1]
{float}
Activation serves two purposes:

  • It allows the page to restore its internal state from data encoded into the URL (the activation context discussed above).
  • It provides coarse approach to validating access to the page.

The later case

...

– validation – is generally concerned with user identity and access; if you have pages that may only be accessed by certain users, you may use the page's activate event handler

...

for verifying that access.

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

...

To some degree, this same effect could be accomplished using a persistent page value, but that requires an active servlet session, and the result is not bookmarkable.

The activate event handler may also return a value, which is treated identically to a return value of a component event request event trigger. This will typically be used in an access validation scenario.

It is common to need to handle multiple page activation scenarios in one page class. You can create multiple activate event handler methods with different arguments, but a better approach is to create one method with an EventContext argument. Tapestry will populate the EventContext argument with all of the activation context arguments, and the EventContext's {{get} method will retrieve and coerce each argument to the desired type. For example:

Code Block
java
java
  . . .

  void onActivate(EventContext eventContext) {

    String color = DEFAULT_COLOR;

    // at least one activation parameter?
    if (eventContext.getCount() > 0) {
      long productId = eventContext.get(Long.class, 0);

      // at least two activation parameters?
      if (eventContext.getCount() > 1) {
        String color = eventContext.get(String.class, 1);
      }
      product = productDAO.getById(productId, color);
    }
  }

  . . .

This combination of action links and context and page context can be put together in any number of ways.

...