第二十讲:tapestry多表单(forms)

源码如下:

MultipleForms1.java

/**
* 项目名称:TapestryStart
* 开发模式:Maven+Tapestry5.x+Tapestry-hibernate+Mysql
* 版本:1.0
* 编写:飞风
* 时间:2012-02-29
*/
package com.tapestry.app.pages;
 
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
 
import com.tapestry.app.pages.MultipleForms2.SearchType;
 
public class MultipleForms1 {
@Property
private String customerName;
 
@Property
private String supplierName;
 
@InjectPage
private MultipleForms2 page2;
 
void onPrepareFromSearchCustomers() {
//可初始化Customers表单元素
}
 
void onPrepareFromSearchSuppliers() {
//可初始化Suppliers表单元素
}
 
Object onSuccessFromSearchCustomers() {
page2.set(SearchType.CUSTOMERS, customerName);
return page2;
}
 
Object onSuccessFromSearchSuppliers() {
page2.set(SearchType.SUPPLIERS, supplierName);
return page2;
}
}
 

MultipleForms1.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">
 
<form t:type="form" t:id="searchcustomers" style="border: medium solid gray">
<t:errors/>
Customer Name: 
<input t:type="TextField" t:id="customerName" t:validate="required, maxlength=10" size="10"/> 
<input type="submit" value="Search Customers"/>
  </form><br/>
 
<form t:type="form" t:id="searchsuppliers" style="border: medium solid gray">
<t:errors/>
Supplier Name: 
<input t:type="TextField" t:id="supplierName" t:validate="required, maxlength=10" size="10"/> 
<input type="submit" value="Search Suppliers"/>
  </form><br/>
</html>

MultipleForms2.java

/**
* 项目名称:TapestryStart
* 开发模式:Maven+Tapestry5.x+Tapestry-hibernate+Mysql
* 版本:1.0
* 编写:飞风
* 时间:2012-02-29
*/
package com.tapestry.app.pages;
 
public class MultipleForms2 {
private SearchType searchType;
 
private String name;
 
public enum SearchType {
CUSTOMERS, SUPPLIERS;
}
 
public void set(SearchType searchType, String lastName) {
this.searchType = searchType;
this.name = lastName;
}
 
 
Object[] onPassivate() {
return new Object[] { searchType, name };
}
 
void onActivate(SearchType searchType, String lastName) {
this.searchType = searchType;
this.name = lastName;
}
 
public String getYourSearch() {
if (searchType == SearchType.CUSTOMERS) {
return "你选择  Customers 名字为: \"" + name + "\".";
}
else {
return "你选择  Suppliers 名字为: \"" + name + "\".";
}
}
}
 

MultipleForms2.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">
${yourSearch}<br/><br/>
<a t:type="pagelink" t:page="MultipleForms1" href="#">返回</a>
</html>

http://localhost/multipleForm/MultipleForms1

转载于:https://my.oschina.net/shootercn/blog/53681

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值