0
votes

I have the following code to delete the selected row from 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>

Bean code

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

I have the getter and setter for selectedProperty too. But when I click the delete link I see the following error.

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)

It doesn't even go to the action method. Can anyone please let me know what mistake I am making?

When I pass argument to delete method and check it is working. But why is f:setPropertyActionListener failing?

Working code

  <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>
2
What is type of selectedProperty? - Piyush Gupta
LocationPropertiesTO - user2017810

2 Answers

2
votes

I think it is related to the missing EL tags within PropertyActionListener.

Try using:

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

That is why the ELException complains about trying to parse a String value into your custom POJO (parse String "locProp").

0
votes

you can do this as follow:

first, pass ID of selected row to your Bean like this:

<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>

row is var in your DataTable.

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

Then, in your deleteProperty() method, find your LocationPropertiesTO object by Id that has been passed as follow:

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

finaly, update your data table.