2015-09-11 59 views
0

我有問題的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); 
} 
+0

我編輯了我的話題,一切都在工作,感謝SantiBailors的回覆非常快。 –

回答

0

我不認爲你可以通過你的User例如在t:context直接這樣。通用對象實例不能直接在客戶端和服務器之間傳遞。您必須將某種引用傳遞給您的實例 - 通常是一個id--您的onActionFromIzbrisi()方法可用於檢索實際對象。

根據the doc for ActionLinkt:context屬性表示

對於鏈路(可選參數)的上下文。此值列表 將被轉換爲字符串幷包含在URI中。

該文檔頁面還顯示瞭如何傳遞對象的示例。

+1

感謝它的工作,我現在將用解決方案編輯我的帖子 –