ZoneRefreshDemoOne : Source Code
ZoneRefreshDemoOne.tml:
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" >
<head>
<title>Zone Refresh demo </title>
</head>
<body>
<h1>ZoneRefresh Demo One</h1>
A demo on the mixin
<a href="${message:componentHomePage}">
ZoneRefresh</a>.
The source code of this demo
is <a href="#" t:type="PageLink"
t:page="test/core/mixin/ZoneRefreshDemoOneSource" target="_blank">here</a>.
<br/><br/>
The linear, quadratic and cubic equations will be displayed in 5 second interval.
<br/>
<br/><br/>
<t:zone style="float:left; width: 850px;" t:mixins='zoneRefresh' t:period='5' t:id='imageZone'>
<t:block id="imageBlock">
${equation} <br/>
<img src="${equationImage}" />
</t:block>
</t:zone>
</body>
</html>
ZoneRefreshDemoOne.java
package com.man.tapestry5Demo.pages.test.core.mixin;
import org.apache.tapestry5.Asset;
import org.apache.tapestry5.Block;
import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.Path;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
public class ZoneRefreshDemoOne {
@Inject
@Path("context:images/linear.gif")
private Asset linear;
@Inject
@Path("context:images/quadratic.gif")
private Asset quadratic;
@Inject
@Path("context:images/cubic.gif")
private Asset cubic;
@Inject
private Block imageBlock;
private Asset[] images;
private static final String[] EQUATIONS = { "Linear", "Quadratic", "Cubic" };
@Persist(PersistenceConstants.SESSION)
@Property
private int index;
public void pageLoaded() {
images = new Asset[] { linear, quadratic, cubic };
}
public String getEquation() {
return EQUATIONS[index];
}
public String[] getEquations() {
return EQUATIONS;
}
public Asset getEquationImage() {
return images[index];
}
/**
*
* This is called every 3 seconds.
*/
Object onRefreshFromImageZone() {
index = index + 1;
if (index >= 3) {
index = index - 3;
}
return imageBlock;
}
}