I have problem with Tapestry 5. When i try to delete user from an table which have action link on cell it wont delete that user, it delete always last user that is on table... here is my code :
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>
EDIT:
All i had to do here is to pass an parameter(Object or ID) in constructor of method for deleting files.
Just replaced
@CommitAfter
void onActionFromIzbrisi() {
session.delete(user);
}
with:
@CommitAfter
void onActionFromIzbrisi(User user) {
session.delete(user);
}
I don't think you can just pass your User
instance in the t:context
directly like that. A generic object instance cannot be passed between client and server directly. You will have to pass some kind of reference to your instance - usually an id - that your onActionFromIzbrisi()
method can use to retrieve the actual object.
According to the doc for ActionLink
the t:context
attribute represents
The context for the link (optional parameter). This list of values will be converted into strings and included in the URI.
That doc page also shows an example of how to pass an object.