tapestry提供了2种经常使用的数据循环显示:loop组件与grid组件,二者没多大区别,loop组件没有提供分页,使用比较灵活,gird组件提供了分页功能,相反本身定义方面没那么灵活,但提供了字段排序的功能。此例子写的比较复杂,由于以前不知道怎么使用loop组件显示string[]数组,所以把例子写下来便于之后查看,其实很简单的首先要把string[]转变成List<String>再使用loop组件显示。源码以下:html
/**
* 项目名称:TapestryStart
* 开发模式:Maven+Tapestry5.x+Tapestry-hibernate+Mysql
* 版本:1.0
* 编写:飞风
* 时间:2012-02-29
*/
package com.tapestry.app.pages;
import java.util.ArrayList;
import java.util.List;
import org.apache.tapestry5.annotations.Property;
public class DataList {
@Property
private String nameOne;
@Property
private String nameTwo;
@Property
private String[] nameOnes;
@Property
private String[] nameTwos;
@Property
private List<String> oneLists;
@Property
private List<String> twoLists;
void setupRender(){
String oneString = "张三/李四/王五/";
nameOnes = oneString.split("/");
oneLists = new ArrayList<String>();
for(String str:nameOnes){
oneLists.add(str);
}
String twoString = "刘备/张飞/关于/";
nameTwos = twoString.split("/");
twoLists = new ArrayList<String>();
for(String str2:nameTwos){
twoLists.add(str2);
}
}
}
<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">
name<br/>
<t:loop source="oneLists" value="nameOne">
${nameOne}<br/>
</t:loop>
<t:grid source="twoLists" add="name" row="nameTwo">
<p:NameCell>
${nameTwo}<br/>
</p:NameCell>
</t:grid>
</html>
http://localhost/loop/datalist