<!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
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>Return To Page (1)</h3>
Sometimes a page can be called from many other pages. If so, it can be tricky for the page to return to the previous page.<br/>
This example shows a way to do it.<br/><br/>
This page creates a Link to itself, complete with the current context (ie. the value of arg1).
It passes the Link to the next page.
<div class="eg">
<t:form class="form-inline" t:id="inputs">
<div class="form-group">
<t:label for="arg1">Current context</t:label>
<t:textfield t:id="arg1"/>
<t:submit/>
</div>
</t:form>
</div>
References:
<a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/Link.html">Link</a>,
<a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/services/PageRenderLinkSource.html">PageRenderLinkSource</a>.<br/><br/>
<t:pagelink page="Index">Home</t:pagelink><br/><br/>
<t:tabgroup>
<t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/navigation/ReturnToPage1.tml"/>
<t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/navigation/ReturnToPage1.java"/>
<t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/returntopage1.css"/>
</t:tabgroup>
</body>
</html>
package jumpstart.web.pages.examples.navigation;
import javax.validation.constraints.NotNull;
import org.apache.tapestry5.Link;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.PageRenderLinkSource;
@Import(stylesheet = "css/examples/returntopage1.css")
public class ReturnToPage1 {
// The activation context
@Property
@NotNull
private String arg1;
// Other pages
@InjectPage
private ReturnToPage2 page2;
// Generally useful bits and pieces
@Inject
private PageRenderLinkSource pageRenderLinkSource;
// The code
// onActivate() is called by Tapestry to pass in the activation context from the URL.
void onActivate(String arg1) throws Exception {
this.arg1 = arg1;
}
// onPassivate() is called by Tapestry to get the activation context to put in the URL.
String onPassivate() {
return arg1;
}
Object onSuccess() {
Link thisPage = pageRenderLinkSource.createPageRenderLinkWithContext(this.getClass(), onPassivate());
page2.set("Hello", thisPage);
return page2;
}
}
.eg {
margin: 20px 0;
padding: 14px;
color: #333;
border: 1px solid #ddd;
border-radius: 6px;
-webkit-border-radius: 6px;
-mox-border-radius: 6px;
}
.eg input.form-control {
width: auto;
}