O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – using DataTable with cell editing support

Let us see how to use the cell editing feature of DataTable:

  1. Create a DataTable component with the editable mode enabled by setting editable to true and editMode to cell, 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>
  2. Implement the cellEdit AJAX event listener method, onCellEdit():
    public void ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required