tapestry的Ajax使用很是簡單,Ajax的頁面無刷新,恰好解決了eventlink、actionlink等組件無刷新,這點在js應用中很是的強大。下面就於eventlink組件爲例。源碼以下:html
/**
* 項目名稱:TapestryStart
* 開發模式:Maven+Tapestry5.x+Tapestry-hibernate+Mysql
* 版本:1.0
* 編寫:飛風
* 時間:2012-02-29
*/
package com.tapestry.app.pages;
import java.util.Date;
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;
public class AJAXEventLink {
@Inject
private Request request;
@InjectComponent
private Zone time2Zone;
@SuppressWarnings("unused")
private Date serverTime1;
@SuppressWarnings("unused")
private Date serverTime2;
void onRefreshPage() {
}
Object onRefreshZone() {
return request.isXHR() ? time2Zone.getBody() : null;
}
public Date getServerTime1() {
return new Date();
}
public Date getServerTime2() {
return new Date();
}
}
<html t:type="layout" title="tapestryStart Index" t:sidebarTitle="Framework Version"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" xmlns:p="tapestry:parameter">
<div style="margin-left: 50px">
<a t:type="eventlink" t:event="refreshPage" href="#">頁面須要刷新</a><br/>
<a t:type="eventlink" t:event="refreshZone" href="#" t:zone="time2Zone">頁面無刷新</a><br/><br/>
serverTime1: ${serverTime1}
<t:zone t:id="time2Zone">
serverTime2: ${serverTime2}
</t:zone><br/>
</div>
</html>