2014-10-31 64 views
1

我想刪除項目中選擇的行,我使用Hibernate和Struts。Struts2 CRUD刪除不工作

<a href="DeletePublication?Id=<s:property value="Id"/>"><img 
        src="${pageContext.request.contextPath}/img/delete.png" width=20px 
        height=20px></a> 

這是我要點擊的鏈接!在struts.xml行動被定義爲:

<action name="DeletePublication" class="de.nak.library.action.PublicationAction" 
     method="delete"> 
     <result type="redirect">ShowPublicationList.action</result> 
     <result type="chain" name="input">ShowPublicationList</result> 
    </action> 

Action類的樣子:

public String delete() { 
    publication = publicationService.loadPublication(publicationId); 
    if (publication != null) { 
     publicationService.deletePublication(publication); 
    } 
    return SUCCESS; 

如果我點擊鏈接,什麼也沒有發生!我試圖在delete方法中設置一個斷點,我發現它甚至沒有被調用。請幫忙!

回答

1

更改這個在struts.xml

<constant name="struts.devMode" value="true" /> 

這將開啓一個開發模式,您可以在控制檯上看到更多的日誌信息。你可能沒有吸氣劑和固化劑的屬性。在屬性中缺少"

<s:a namespace="onthepackage" action="DeletePublication"><s:param name="Id" value="%{Id}"/><img 
    src="<s:url value='/img/delete.png'/>" width="20px" 
    height="20px"> 
</s:a> 
+0

謝謝你的回答!我打開devMode,仍然沒有有用的錯誤!我試過你的代碼示例,不幸的是沒有效果:(網址是正確的,但方法仍然沒有調用,並且有getter和setters ... – hypePG 2014-10-31 21:58:02

+0

發佈一個完整的'struts.xml'。 – 2014-10-31 22:28:39

+0

謝謝!錯誤,這是一個設置錯誤:(所以愚蠢的錯誤! – hypePG 2014-11-02 13:21:43

0

而是採用直接<a href="">,使用<s:url>才能到DeletePublication行動。然後用<s:url>的參考<a href='<s:property value="#ref"/>'