I am using PrimeFaces 3.5 and I am implementing the DataTable component - ContextMenu . However, I want to delete the row by clicking on one cell in the row.
My JSF page:
<h:form id="form"> <p:growl id="messages" showDetail="true" /> <p:contextMenu for="productID" widgetVar="cMenu"> <p:menuitem value="Edit Cell" icon="ui-icon-search" onclick="productService.showCellEditor();return false;" /> <p:menuitem value="Delete Row" icon="ui-icon-search" onclick="productService.delete();return false;" /> </p:contextMenu> <p:dataTable id="productID" var="product" value="#{productService.getListOrderedByDate()}" editable="true" editMode="cell" widgetVar="productTable" paginator="true" rows="10" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15"> <f:facet name="header"> Airbnb Product </f:facet> <p:ajax event="cellEdit" listener="#{productService.onCellEdit}" update=":form:messages" /> <p:column headerText="id" style="width:15%"> <p:cellEditor> <f:facet name="output"> <h:outputText value="#{product.id}" /> </f:facet> <f:facet name="input"> <p:inputText value="#{product.id}" style="width:96%" /> </f:facet> </p:cellEditor> ... </p:column> </p:dataTable> </h:form>
I applied the delete method in my service, which should work. However, when I click the delete button in my context menu, nothing happens. What could be the cause of the problem?
UPDATE
I liked the PF page:
public void delete() { log.info("Deleting data:"); log.info(selectedRow.getId());
and my datatable:
<p:contextMenu for="productID" widgetVar="cMenu"> <p:menuitem value="Edit Cell" icon="ui-icon-search" onclick="productService.showCellEditor();return false;" /> <p:menuitem value="Delete" update="productID" icon="ui-icon-close" actionListener="#{productService.delete}" /> </p:contextMenu> <p:dataTable id="productID" var="product" value="#{productService.getListOrderedByDate()}" editable="true" editMode="cell" widgetVar="productTable" paginator="true" rows="10" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15" selection="#{productService.selectedRow}" selectionMode="single" rowKey="#{product.id}">
However, when I want to get the identifier from the selected row, I get a NullPointerException . I really appreciate your answer!
source share