Passing Data Between Pages

Tapestry's policy of doing Post/Redirect/Get can make it a bit tricky for an event request to result in data being passed to the next page.
Here are 5 ways to do it:

<!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="">
    <style type="text/css">
        .noeg       { padding-bottom: 14px; }
<body class="container">
    <h3>Passing Data Between Pages</h3>
    Tapestry's policy of doing <a href="">Post/Redirect/Get</a> can make it a 
    bit tricky for an event request to result in data being passed to the next page.<br/>   
    Here are 5 ways to do it:<br/>

            <strong>By Activation Context</strong><br/>
            This is the most used technique. It's usually employed to pass an <strong>identifier</strong>, eg. productId.

            <div class="eg">
                <t:form t:id="useactivationcontext">
                    <t:eventlink event="useActivationContext">Use activation context to pass id <em>1</em></t:eventlink>.
            <strong>By Query String</strong><br/>
            This may be the most appropriate way to pass <strong>filter criteria</strong> because, 
            arguably, it produces the most RESTful URL in that situation.

            <div class="eg">
                <t:form t:id="usequerystring">
                    <t:eventlink event="useQueryString">Use query string to pass partial name = <em>humpty</em></t:eventlink>.

            <strong>By Persist</strong><br/>
            This is usually the most appropriate way to pass <strong>whole objects, lengthy data, or data you don't 
            want to be visible in a URL</strong>

            <div class="eg">
                <t:form t:id="usepersist">
                    <t:eventlink event="usePersist">Use @Persist to pass a Person's first and last name</t:eventlink>.

        <li class="noeg">
            <strong>By Session State Objects</strong><br/>
            This is the best way to share data <strong>between multiple pages</strong> as in a <strong>wizard or a shopping basket</strong>.<br/>
            See the <em>Sharing Across Multiple Pages</em> example.

            <strong>By Services</strong><br/>
            This is the best way to share an object <strong>across the whole application</strong>.<br/>
            See the <em>Sharing Across the Application</em> example.

    <t:pagelink page="Index">Home</t:pagelink><br/><br/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/state/PassingDataBetweenPages.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/state/"/>
        <t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/plain.css"/>

package jumpstart.web.pages.examples.state;

import org.apache.tapestry5.Link;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.InjectPage;

public class PassingDataBetweenPages {

    private PassingByActivationContext byActivationContextPage;

    private PassingByQueryString byQueryStringPage;
    private PassingByPersist byPersistPage;

    Object onUseActivationContext() {
        return byActivationContextPage;

    Object onUseQueryString() {
        Link link = byQueryStringPage.set("humpty");
        return link;

    Object onUsePersist() {
        byPersistPage.set("Humpty", "Dumpty");
        return byPersistPage;

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