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

源码如下:

MultipleForms1.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.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
* 网址: http://www.flywind.org
* 版本: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

你可能感兴趣的:(第二十讲:tapestry多表单(forms))