title: How to put a delete button for an object in a Primefaces data table?
body: <p>I have a data table with a couple of rows and I have a column where I have a form with a simple button that deletes the object in that row.</p>
  
  <p>So first the working version:</p>
  
  <pre><code>&lt;h:dataTable value="#{actorTableBackingBean.allActors}" 
      var="actor" styleClass="table table-bordered"&gt;
  
      &lt;h:column headerText="Actor Name" sortBy="#{actor.firstName}"&gt;
          &lt;h:outputText value="#{actor.firstName}"/&gt;
      &lt;/h:column&gt;
  
      &lt;h:column headerText="Actor Detail"&gt;
          &lt;h:form&gt;
              &lt;h:commandButton value="Delete Actor" 
                  styleClass="btn btn-primary" 
                  action="#{actorTableBackingBean.deleteActor(actor.actorId)}"/&gt;
           &lt;/h:form&gt;
      &lt;/h:column&gt;
  &lt;/h:dataTable&gt;
  </code></pre>
  
  <p>And this is what <strong>deleteActor</strong> method looks like: </p>
  
  <pre><code>public String deleteActor(String id){
      removeActorWithId(id);
      return "/allActors.xhtml";
  }
  
  private void removeActorWithId(String id){
      int idk = Integer.parseInt(id);
      for(Actor a:allActors){
          if(a.getActorId() == idk){
              allActors.remove(a);
              return;
          }
      }
  }
  </code></pre>
  
  <p>So this exactly works as expected as it is.</p>
  
  <p>However, when I use a Pagination Data table of Primefaces as shown in <a href="http://www.primefaces.org/showcase/ui/datatablePagination.jsf" rel="noreferrer">here</a>, delete button works only for the FIRST ROW in the second case and only for the first time.
  When I click on button "Delete" for other rows, simply nothing happens. 
  What might be the reason? </p>
  
  <p>For second situation just put the &lt; form > tags around p:dataTable as seen in the link and replace everything like h:dataTable to p:dataTable and p:column etc...</p>