第三十四講:tapestry Ajax actiontlink無刷新頁面

源碼以下:html

AJAXActionLink.javajava

/**
 * 項目名稱: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 AJAXActionLink {
 
@Inject
private Request reauest;
 
@InjectComponent
private Zone time2Zone;
 
void onActionFromRefreshPage(){}
 
Object onActionFromRefreshZone(){
return reauest.isXHR()? time2Zone.getBody():null;
}
 
public Date getServerTime1(){
return new Date();
}
 
public Date getServerTime2(){
return new Date();
}
}
 

AJAXActionLink.tmlsql

<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="actionlink" t:id="refreshPage" href="#">ActionLink刷新頁面</a><br/>
<a t:type="actionlink" t:id="refreshZone" href="#" t:zone="time2Zone">ActionLink AJAX無刷新</a><br/><br/>
 
serverTime1:  ${serverTime1}
<t:zone t:id="time2Zone">
serverTime2:  ${serverTime2}
</t:zone><br/>
</div>
</html>
相關文章
相關標籤/搜索