第十讲:tapestry通过地址栏传值@PageActivationContext

tapestry通过地址栏传值常用的有:通过组件的context传值、通过activate(),passivate传值、通过@PageActivationContext传值。@PageActivationContext等同于activate(),passivate。代码如下:

 

ActivationContext.java

/**
* 项目名称:TapestryStart
* 开发模式:Maven+Tapestry5.x+Tapestry-hibernate+Mysql
* 网址: http://www.flywind.org
* 版本:1.0
* 编写:飞风
* 时间:2012-02-29
*/
package com.tapestry.app.pages;
 
import org.apache.tapestry5.annotations.PageActivationContext;
import org.apache.tapestry5.annotations.Property;
 
public class ActivationContext {
 
@Property
private String strOne;
 
//传递strOne到浏览器地址栏
String onPassivate(){
return strOne;
}
 
//从地址栏中获得strOne值,注意:当传递的值是中文是会被转码,所以看不到中文。
//当做检索的时候想通过地址栏传递查询变量时,可使用ajax不刷新查看中文。
void onActivate(String strOne){
this.strOne = strOne;
}
 
//@PageActivationContext是onPassivate()与onActivate()2个函数的封装。
//使用@PageActivationContext就不用在写onPassivate()与onActivate()了
//跟@Property类似。
@Property
@PageActivationContext
private String strTwo;
}
 

ActivationContext.tml

<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">
<a t:type="pagelink" t:page="ActivationContext" t:context="literal:5">把5传递到ActivationContext页面</a><br/><br/><br/>
<t:form t:id="form1">
<input t:type="textfield" t:id="strOne" value="strOne"/>
<input type="submit" value="传递strOne值"/>
</t:form>
<t:form t:id="form2">
<input t:type="textfield" t:id="strTwo" value="strTwo"/>
<input type="submit" value="传递strTwo值"/>
</t:form>
</html>

http://localhost/activationcontext

你可能感兴趣的:(第十讲:tapestry通过地址栏传值@PageActivationContext)