<!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>AJAX ActionLink</h3>
<noscript class="js-required">
${message:javascript_required}
</noscript>
ActionLink has the same AJAX capabilities as EventLink.
<div class="eg">
<t:actionlink t:id="refreshPage">Refresh whole page - this ActionLink is not AJAX-enabled</t:actionlink><br/>
<t:actionlink t:id="refreshZone" zone="time2Zone">Refresh only serverTime2 - this ActionLink is AJAX-enabled</t:actionlink><br/><br/>
serverTime1: ${serverTime1}
<t:zone t:id="time2Zone" id="time2Zone">
serverTime2: ${serverTime2}
</t:zone>
</div>
References:
<a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/ActionLink.html">ActionLink</a>,
<a href="http://tapestry.apache.org/ajax-and-zones.html">Ajax and Zones</a>,
<a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/Zone.html">Zone</a>,
<a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/services/Request.html">Request</a>,
<a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html">@Inject</a>,
<a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/annotations/InjectComponent.html">@InjectComponent</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/ajax/AjaxActionLink.tml"/>
<t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/ajax/AjaxActionLink.java"/>
<t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/js.css"/>
</t:tabgroup>
</body>
</html>
package jumpstart.web.pages.examples.ajax;
import java.util.Date;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.ajax.AjaxResponseRenderer;
// Some time soon, redirect it to the AjaxEventLink example.
@Deprecated
@Import(stylesheet = "css/examples/js.css")
public class AjaxActionLink {
// Generally useful bits and pieces
@Inject
private Request request;
@InjectComponent
private Zone time2Zone;
@Inject
private AjaxResponseRenderer ajaxResponseRenderer;
// The code
void onActionFromRefreshPage() {
// This method isn't needed, because there's nothing to do - when the page renders it will call getServerTime1()
// and getServerTime2().
}
void onActionFromRefreshZone() {
if (request.isXHR()) {
ajaxResponseRenderer.addRender(time2Zone);
}
}
public Date getServerTime1() {
return new Date();
}
public Date getServerTime2() {
return new Date();
}
}
.eg {
margin: 20px 0;
padding: 14px;
color: #888;
border: 1px solid #ddd;
border-radius: 6px;
-webkit-border-radius: 6px;
-mox-border-radius: 6px;
}
.js-required {
color: red;
display: block;
margin-bottom: 14px;
}
.js-recommended {
color: red;
display: block;
margin-bottom: 14px;
}