actionlink與eventlink組件很是類似,都是執行一個事件,在代碼編寫上有一點點差別。源代碼以下:html
MyEvent.javajava
/**
* 項目名稱:TapestryStart
* 開發模式:Maven+Tapestry5.x+Tapestry-hibernate+Mysql
* 版本:1.0
* 編寫:飛風
* 時間:2012-02-29
*/
package com.tapestry.app.pages;
import org.apache.tapestry5.annotations.PageActivationContext;
import org.apache.tapestry5.annotations.Property;
public class MyEvent {
@Property
@PageActivationContext
private int count;
//執行eventlink遞增長+1,newCount就是默認值1
void onAdd(int newCount){
count += newCount;
}
//執行actionlink遞增長+2,meCount就是默認值2
void onActionFromAddTwo(int meCount){
count += meCount;
}
//設置爲0
void onClear(){
count = 0;
}
}
MyEvent.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="color:#ff6600">${count}</div>
<t:eventlink t:event="add" t:context="literal:1">單擊遞增1,初始值爲1</t:eventlink><br/>
<t:actionlink t:id="addTwo" t:context="literal:2">單擊遞增2,初始值爲2</t:actionlink><br/>
<a href="#;" t:type="eventlink" t:event="clear">清除</a>
</html>
http://localhost/myevent