title: JSF: Cancel datatable row edit after data submission in Primefaces
body: <p>I'm developing a web-app in JSF 2.1 + Primefaces 5.1. I have a datatable with editable rows. I catch the <code>rowEdit</code> event and call a DB procedure to do some validations of the new data and update the record when the user clicks the "check" button. But there's a problem: the datatable row in the GUI is updated whether the validations succeed or fail. I want the changes in the row data to be reversed to their previous state if the validations done in the DB procedure fail. How can I do that?</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;p:dataTable id="users_table_id" var="user" value="#{usersBean.users}" rowKey="#{user.id}" paginator="true"
              paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                 rowsPerPageTemplate="5,10,15" emptyMessage="#{msgs.no_records}" sortBy="#{user.id}" sortOrder="ascending" rows="15" editable="true"&gt;
              &lt;f:facet name="header"&gt;
                  #{msgs.users}               
              &lt;/f:facet&gt;
              &lt;p:ajax event="rowEdit" listener="#{usersBean.onRowEdit}"/&gt;
              &lt;p:ajax event="rowEditInit" listener="#{usersBean.onRowEditInit}"/&gt;
              &lt;p:column headerText="#{msgs.id}" sortBy="#{user.id}" styleClass="centered-column"&gt;
                  #{user.id}
              &lt;/p:column&gt;          
              &lt;p:column headerText="#{msgs.description}" sortBy="#{user.description}" styleClass="centered-column"&gt;
                  &lt;p:cellEditor&gt;
                      &lt;f:facet name="output"&gt;#{user.description}&lt;/f:facet&gt;
                      &lt;f:facet name="input"&gt;&lt;p:inputText value="#{user.description}" styleClass="editable-cell"/&gt;&lt;/f:facet&gt;
                  &lt;/p:cellEditor&gt;
              &lt;/p:column&gt; 
              ...
              &lt;p:column styleClass="datatable-row-editor"&gt;
                  &lt;p:rowEditor/&gt;
              &lt;/p:column&gt;
  &lt;/p:dataTable&gt;
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>@ManagedBean
  @ViewScoped
  public class UsersBean implements Serializable {
  
      private List&lt;DtoUser&gt; users;
  
      public void onRowEdit(RowEditEvent event) {
          logger.entry();
          DtoUser dtoUser = (DtoUser)event.getObject();
          this.updateUser(dtoUser);
          logger.exit();
      }
  
      public void updateUser(DtoUser dtoUser) { 
          try {
              logger.entry(dtoUser);
              DtoBoUsers dtoBoUsers = dtoUser.toDtoBoUsers();
              DtoTypeGenericResponse genericResponse = usersService.updateUser(dtoBoUsers);
              if (genericResponse.isError()) {
                  // error in user update
              } else {
                  // update successful
              }
              logger.exit(dtoUser);
          } catch (Exception e) {
              logger.error(ExceptionUtils.getStackTrace(e.fillInStackTrace()));
          }
      }
  }
  </code></pre>