<!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_3.xsd">
<head>
<link rel="stylesheet" type="text/css" href="${context:css/examples/js.css}"/>
</head>
<body>
<h1>AJAX EventLink</h1>
<noscript class="js-required">
${message:javascript_required}
</noscript>
This page demonstrates how easily <a href="http://en.wikipedia.org/wiki/AJAX">AJAX</a> behaviour can be given to an EventLink,
without writing any JavaScript.
In this demonstration, note how the whole page is refreshed when you click the first link, whereas only time2 is updated when you
click on the second, AJAX-enabled, link.
<div class="eg">
<a t:type="eventlink" t:event="refreshPage" href="#">Refresh whole page - this EventLink is not AJAX-enabled</a><br/>
<a t:type="eventlink" t:event="refreshZone" t:zone="time2Zone" href="#">Refresh only server time 2 - this EventLink is AJAX-enabled</a><br/><br/>
serverTime1: ${serverTime1}
<t:zone t:id="time2Zone" id="time2Zone">
serverTime2: ${serverTime2}
</t:zone>
</div>
We gave AJAX behaviour to the second link by specifying a <code>zone</code> parameter on it and putting a Zone component around serverTime2.<br/><br/>
<strong>Without zone</strong> specified on the first EventLink, clicking it results in <strong>Get/Redirect/Get</strong>.<br/>
The event handler returns a "redirect" to the <em>page to render</em>. This involves 2 round trips to the server.<br/><br/>
<strong>With zone</strong> specified on the second EventLink, clicking it results in <strong>Post/Partial-Response</strong>. <br/>
The event handler returns a <em>component or block to update</em>. This involves only 1 round trip to the server.<br/><br/>
References:
<a href="http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/corelib/components/EventLink.html">EventLink</a>,
<a href="http://tapestry.apache.org/ajax-and-zones.html">Ajax and Zones</a>,
<a href="http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/corelib/components/Zone.html">Zone</a>,
<a href="http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/services/Request.html">Request</a>,
<a href="http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html">@Inject</a>,
<a href="http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/annotations/InjectComponent.html">@InjectComponent</a>.<br/><br/>
Some statistics: for this page the AJAX traffic is less than 300 bytes, whereas the non-AJAX traffic is over 9,000 bytes.
The AJAX link generates 1 POST whereas the non-AJAX generates 2 GETs (which is normal for EventLink).<br/><br/>
<a t:type="pagelink" t:page="Index" href="#">Home</a><br/><br/>
<t:sourcecodedisplay src="/web/src/main/java/jumpstart/web/pages/examples/ajax/AjaxEventLink.tml"/>
<t:sourcecodedisplay src="/web/src/main/java/jumpstart/web/pages/examples/ajax/AjaxEventLink.java"/>
<t:sourcecodedisplay src="/web/src/main/java/jumpstart/web/css/examples/js.css"/>
</body>
</html>