Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: wordsmithing

...

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.

Page activation uses Tapestry's Component Event mechanism. See Component Events for details.

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

...

The activate event handler may also return a value, which is treated identically to a return value of a component event request event triggermethod. 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 (see the "Multiple Method Matches" section 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 context argumentsparameters, and the EventContext's {{get} method will retrieve and coerce each argument parameter 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);
    }
  }

  . . .

...