Book Image

Tapestry 5: Building Web Applications

Book Image

Tapestry 5: Building Web Applications

Overview of this book

Table of Contents (17 chapters)
Tapestry 5
Credits
About the Author
About the Reviewers
Preface
Foreword
Where to Go Next

Using Page Activation Context


Tapestry 5 has a special way to pass a value from one page to another. Let's see how it works. First of all, we need to make the page "activatable", which means that we should add two methods—onActivate and onPassivate to the page. They will be invoked by Tapestry at the appropriate moments of the HTTP request life cycle. In this case, the Another page allows the @Persist annotation to be removed and adds the mentioned methods, like the following listing shows:

package com.packtpub.t5first.pages;
public class Another
{
private String passedMessage;
public String getPassedMessage()
{
return passedMessage;
}
public void setPassedMessage(String passedMessage)
{
this.passedMessage = passedMessage;
}
void onActivate(String message)
{
System.out.println("Another page is activated! The
message is: " + message);
this.passedMessage = message;
}
String onPassivate()
{
System.out.println("Another page is passivated...");
return passedMessage;
}
}

Now let's run the application...