2016-02-17 36 views
0

我有下面的代碼從對刪除選定行:數據表刪除所選行的數據表

<p:commandLink id="deleteProp" action="#{locationBean.deleteProperty}" styleClass="datatabletext" update="locationProperties" process="@this"> 
<h:graphicImage value="/resources/images/delete.gif" /> 
<f:setPropertyActionListener target="#{locationBean.selectedProperty}" value="locProp" /> 
</p:commandLink> 

豆代碼

public void deleteProperty() { 
    System.out.println("selec "+selectedProperty); 
    locProps.remove(selectedProperty); 
} 

我有selectedProperty getter和setter了。但是當我點擊刪除鏈接時,我看到以下錯誤。

WARNING: Cannot convert locProp of type class java.lang.String to class TO.LocationPropertiesTO 
javax.el.ELException: Cannot convert locProp of type class java.lang.String to class TO.LocationPropertiesTO 
at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:416) 

它甚至沒有進入操作方法。任何人都可以讓我知道我在做什麼錯誤?

當我通過參數刪除方法,並檢查它正在工作。但爲什麼f:setPropertyActionListener失敗?

工作代碼

<p:commandLink id="deleteProp" rendered="#{fn:length(locationBean.locProps)>1}" 
            action="#{locationBean.deleteProperty(locProp)}" 
            styleClass="datatabletext" update="locationProperties" 
            process="@this"> 
            <h:graphicImage value="/resources/images/delete.gif" /> 

</p:commandLink> 
+0

什麼是selectedProperty的類型? –

+0

LocationPropertiesTO – user2017810

回答

2

我認爲這與PropertyActionListener中缺少的EL標籤有關。

嘗試使用:

<f:setPropertyActionListener target="#{locationBean.selectedProperty}" value="#{locProp}" /> 

這就是爲什麼ELException抱怨試圖解析字符串值到自定義POJO(解析字符串「locProp」)。

+0

謝謝!是的,我糾正它,現在它工作! – user2017810

0

,你可以做到這一點如下:

第一,通過選擇行的ID給你的Bean是這樣的:

<p:commandLink id="deleteProp" action="#{locationBean.deleteProperty}" styleClass="datatabletext" update="locationProperties" process="@this"> 
<h:graphicImage value="/resources/images/delete.gif" /> 
<f:setPropertyActionListener target="#{locationBean.selectedProperty}" value="locProp" /> 
<f:param name="deletingRowId" value="#{row.id}" /> 
</p:commandLink> 

排在你的DataTable變種。

<p:dataTable ... var="row" ... /> 

然後,在你deleteProperty()方法,找到ID您LocationPropertiesTO對象已被如下決議:

Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); 
String id = params.get("deletingRowId"); 
LocationPropertiesTO lo = findLObyId(id, locProps); 
locProps.remove(selectedProperty); 

finaly,更新您的數據表。

+0

嗨。請參閱我的編輯。我想知道爲什麼f:setPropertyActionListener失敗 – user2017810

+0

什麼是您的jsp代碼中的locProp? –

+0

似乎'邏輯 –