How to update specific row in Primefaces datatable

primefaces

Solution

You `p:ajax` tag is inside `p:dataTable` no in some specific row or column, so you cent so easy update some relative component id. You can with help of `RequestContext` update specific component in cell. So, remove `update` from `p:ajax` and add this to your `onEditLabel` method:

RequestContext.getCurrentInstance().update(
  s.getClientId(FacesContext.getCurrentInstance()) +
  ":" + event.getRowIndex() +
  ":isAutomatic"
);

As you can see, id of component inside cell has row number before id you assigned.

Problem

Primefaces 3.5, Mojarra 2.1.14. This is my PF datatable, it contains one non-editable boolean column named 'automatic', and editable 'label' column: ``` <p:dataTable value="#{bean.contents}" paginator="true" var="row" editable="true" editMode="cell" rows="25" rowsPerPageTemplate="10,25,50" id="list"> <p:column> <f:facet name="header"><h:outputText value="header1" /></f:facet> <p:selectBooleanCheckbox value="#{row.automatic}" disabled="true" id="isAutomatic"></p:selectBooleanCheckbox> </p:column> <p:column> <f:facet name="header"><h:outputText value="header2" /></f:facet> <p:cellEditor> <f:facet name="output"> <h:outputText value="#{row.label}"></h:outputText> </f:facet> <f:facet name="input"> <p:inputText value="#{row.label}"></p:inputText> </f:facet> </p:cellEditor> </p:column> <p:ajax event="cellEdit" process="@this" listener="#{myBean.onEditLabel}" update="isAutomatic"/> </p:dataTable> ``` Cell edit event listener: ``` public void onEditLabel(CellEditEvent event) { Object oldValue = event.getOldValue(); Object newValue = event.getNewValue(); if(newValue != null && !newValue.equals(oldValue)) { DataTable s = (DataTable) event.getSource(); MyEntity d = (MyEntity) s.getRowData(); try { d.setAutomatic(false); myDAO.save(d); addMessage("Change saved!"); } catch (Exception ex) { addErrorMessage("Label could not be saved!"); getFacesContext().validationFailed(); } } } ``` The cell editor works, sends data to listener, and it is correctly persisted to the database. The 'automatic' flag is also cleared by cell edit event listener, and gets correctly persisted to the database. The problem is that 'automatic' checkbox is not updated on the client. I also tried ``` <p:ajax event="cellEdit" process="@this" listener="#{myBean.onEditLabel}" update="list"/> ``` which correctly updated the checkbox, but also causes focus to be lost, and wastes bandwidth. How can I update just a specific cell after cellEdit event is fired?

Original source