Variable Parameters (2)

Person Id
Look at the URL of this page. It is the page render request from the PageLink, and the activation context is at the end.

References: If, EventContext, Type Coercion, ValueEncoder, PageLink, Page Render Requests, Page Activation.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<!-- We need a doctype to allow us to use special characters like &nbsp; 
     We use a "strict" DTD to make IE follow the alignment rules. -->
<html xmlns:t="">
<body class="container">
    <h3>Variable Parameters (2)</h3>
    <div class="eg">
        <t:if test="message">
            <div class="alert alert-danger">
        <t:if test="!message">
            <t:beandisplay object="this" include="mode,personId"/>

        <t:pagelink t:page="examples/navigation/VariableParameters1">Return</t:pagelink>

    Look at the URL of this page. 
    It is the page render request from the PageLink, and the <strong>activation context</strong> is at the end.<br/><br/>
    <a href="">If</a>, 
    <a href="">EventContext</a>, 
    <a href="">Type Coercion</a>, 
    <a href="">ValueEncoder</a>, 
    <a href="">PageLink</a>, 
    <a href="">Page Render Requests</a>, 
    <a href="">Page Activation</a>.<br/><br/>

    <t:pagelink t:page="Index">Home</t:pagelink><br/><br/>

        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/navigation/VariableParameters2.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/navigation/"/>
        <t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/plain.css"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/models/"/>

package jumpstart.web.pages.examples.navigation;

import jumpstart.web.models.Mode;

import org.apache.tapestry5.EventContext;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Property;

@Import(stylesheet = "css/examples/plain.css")
public class VariableParameters2 {

    // The activation context

    private Long personId;

    private Mode mode;
    private String message;

    // The code

    // onActivate() is called by Tapestry to pass in the activation context from the URL.

    void onActivate(EventContext eventContext) {
        int parameterCount = eventContext.getCount();
        if (parameterCount == 1) {
            mode = eventContext.get(Mode.class, 0);
        else if (parameterCount == 2) {
            mode = eventContext.get(Mode.class, 0);
            personId = eventContext.get(Long.class, 1);
        else {
            message = "Wrong number of parameters received. Expected 1 or 2, found " + parameterCount + ".";


.eg {
                margin: 20px 0;
                padding: 14px;
                border: 1px solid #ddd;
                border-radius: 6px;
                -webkit-border-radius: 6px;
                -mox-border-radius: 6px;

package jumpstart.web.models;

public enum Mode {