Time for action – using DataTable with cell editing support
Let us see how to use the cell editing feature of DataTable:
- Create a DataTable component with the editable mode enabled by setting
editable
totrue
andeditMode
tocell
, as shown in the following code:<p:dataTable id="usersTbl" var="user" value="#{adminController.users}" editable="true" editMode="cell"> <p:ajax event="cellEdit" listener="#{adminController.onCellEdit}"/> <p:column headerText="FirstName"> <p:cellEditor> <f:facet name="output"> <h:outputText value="#{user.firstName}" /> </f:facet> <f:facet name="input"> <p:inputText value="#{user.firstName}"/> </f:facet> </p:cellEditor> </p:column> </p:dataTable>
- Implement the
cellEdit
AJAX event listener method,onCellEdit...