我有問題的Tapestry 5.當我嘗試刪除用戶從一個表格有單元格上的行動鏈接它不會刪除該用戶,它總是刪除最後一個用戶是在桌子上...這裏是我的代碼:使用休眠和tapestry JAVA
ViewAllUsers.java
public class ViewAllUsers {
@Inject
private Session session;
@Property
@SessionState
private User loginUser;
@Property
@Persist
private User user;
public List<User> getAllUsers() {
return session.createCriteria(User.class).list();
}
@CommitAfter
void onActionFromIzbrisi() {
session.delete(user);
}
}
ViewAllUsers.tml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
xmlns:p="tapestry:parameter">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title></title>
</head>
<body>
<t:Alerts />
<t:Grid t:source="allusers" t:add="Izbrisi,Edit" t:row="user">
<p:izbrisiCell>
<t:actionlink t:id="izbrisi" t:context="user">Delete</t:actionlink>
</p:izbrisiCell>
<p:editCell>
<t:PageLink t:page="EditUser" t:id="edit" t:context="user"> Edit </t:PageLink>
</p:editCell>
<p:deleteOptionCell>
</p:deleteOptionCell>
</t:Grid>
</body>
</html>
編輯:
我所要做的就是在方法的構造函數中傳遞一個參數(Object或ID)來刪除文件。
剛剛更換
@CommitAfter
void onActionFromIzbrisi() {
session.delete(user);
}
有:
@CommitAfter
void onActionFromIzbrisi(User user) {
session.delete(user);
}
我編輯了我的話題,一切都在工作,感謝SantiBailors的回覆非常快。 –