【发布时间】:2016-02-17 04:15:14
【问题描述】:
我有以下代码从 p:datatable 中删除选定的行
<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)
它甚至没有进入 action 方法。谁能告诉我我犯了什么错误?
当我将参数传递给 delete 方法并检查它是否正常工作时。但是为什么 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>
【问题讨论】:
-
selectedProperty 的类型是什么?
-
LocationPropertiesTO
标签: jsf primefaces