思路:在UserList页面传递user的id到修改也UesrUpdate页面,再查询出全部对应的数据。html
修改UserList.tml页面,代码以下:java
<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">
<style>
.table{border-collapse: collapse; }
.table td,table th{border:1px solid #999; padding:5px;"}
</style>
<t:pagelink page="crud/UserCreate">添加用户</t:pagelink><br/><br/>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
<tr>
<th scope="col">id</th>
<th scope="col">用户名</th>
<th scope="col">年龄</th>
<th scope="col">时间</th>
<th scope="col">操做</th>
</tr>
<tr t:type="loop" t:source="users" t:value="user">
<td>${user.id}</td>
<td>${user.name}</td>
<td>${user.age}</td>
<td>${user.time}</td>
<td><t:pagelink page="crud/UserUpdate" t:context="${user.id}">修改</t:pagelink></td>
</tr>
</table>
</html>
在com.tapestry.app.pages.crud包里添加UserUpdate.java,在webapp/crud下增长UserUpdate.tml代码以下:web
UserUpdate.javasql
/**
* 项目名称:TapestryStart
* 开发模式:Maven+Tapestry5.x+Tapestry-hibernate+Mysql
* 版本:1.0
* 编写:飞风
* 时间:2012-02-29
*/
package com.tapestry.app.pages.crud;
import org.apache.tapestry5.annotations.PageActivationContext;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import com.tapestry.app.entities.User;
import com.tapestry.app.services.StartDAO;
public class UserUpdate {
//接收页面传来的id值
@PageActivationContext
private Long id;
//设置user可读写
@Property
private User user;
//导入服务
@Inject
private StartDAO dao;
//页面加载时运行
void onPrepare(){
//user为空数据时根据页面传递过来的id查询数据
if(user == null){
user = dao.findByID(User.class, id);
}
}
//提交表单保存user数据
Object onSuccess(){
dao.update(user);
return UserList.class;
}
}
UserUpdate.tmlapache
<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">
<t:form>
<t:errors/>
<p>用户名:<t:textfield t:id="name" value="user.name" t:validate="required"/></p>
<p>年龄:<t:textfield t:id="age" value="user.age" t:validate="required"/></p>
<p><input type="submit" value="保存"/><t:pagelink page="crud/UserList">返回查看页面</t:pagelink></p>
</t:form>
</html>
查看http://localhost/crud/userlist修改数据也作好了。app