Passing Data Between Pages: by Persist

You asked for null null.

Return
This page used @Persist to save its data through the redirection.
@Persist is usually the most appropriate way to pass whole objects, lengthy data, or data you don't want to be visible in a URL.

In this example we have used the FLASH strategy which stores the field in your session only temporarily - until it is displayed.

For more information see the Storing Data in a Page example.

Home


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- 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="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
<body class="container">
    <h3>Passing Data Between Pages: by Persist</h3>

    <div class="eg">
        <p>You asked for ${name}.</p>
        <t:eventlink event="return">Return</t:eventlink>
    </div>

    This page used <code>@Persist</code> to save its data through the redirection.<br/> 
    <code>@Persist</code> 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>.<br/><br/>
    
    In this example we have used the FLASH strategy which stores the field in your session only temporarily - until it is displayed.<br/><br/>
    
    For more information see the Storing Data in a Page example.<br/><br/>

    <t:eventlink event="gohome">Home</t:eventlink><br/><br/>
    
    <t:tabgroup>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/state/PassingByPersist.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/state/PassingByPersist.java"/>
        <t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/olive.css"/>
    </t:tabgroup>
</body>
</html>


package jumpstart.web.pages.examples.state;

import jumpstart.web.pages.Index;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.ioc.annotations.Inject;

/**
 * This page demonstrates using page persistence to remember data through the redirect. The default strategy for Persist is 
 * to save the data in the session, but this can be overridden, eg. we override it to the FLASH strategy.
 */
@Import(stylesheet="css/examples/olive.css")
public class PassingByPersist {

    // Work fields

    @Persist(PersistenceConstants.FLASH)
    private String firstName;

    @Persist(PersistenceConstants.FLASH)
    private String lastName;

    // Generally useful bits and pieces

    @Inject
    private ComponentResources componentResources;

    // The code

    // set() is public so that other pages can use it to set up this page.

    public void set(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public String getName() {
        return firstName + " " + lastName;
    }

    Object onReturn() {
        componentResources.discardPersistentFieldChanges();
        return PassingDataBetweenPages.class;
    }

    Object onGoHome() {
        componentResources.discardPersistentFieldChanges();
        return Index.class;
    }
}


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