title: How to remove element from datatable
body: <p>A simple application that uses Primefaces <a href="http://www.primefaces.org/showcase/ui/data/datatable/selection.xhtml" rel="nofollow">datatables with radio button selection</a> doesn't behave properly. 
  When I choose an element with radio button, the <code>event</code> argument is <code>null</code> in <code>delete()</code> method, therefore the selected row can't be removed from the datatable.</p>
  
  <p><strong>view.xhtml</strong> // <em>Here is where I get problems</em></p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://xmlns.jcp.org/jsf/core"&gt;
  &lt;h:head&gt;
      &lt;title&gt;Event List&lt;/title&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
      &lt;h:form&gt;
          &lt;p:dataTable id="eventlist" var="event" value="#{eventBean.eventlist}" selection="#{eventBean.selectedEvent}" rowKey="#{event.id}" scrollable="true" scrollHeight="200" style="width:500px;"&gt;
              &lt;f:facet name="header"&gt;
                  Event List
              &lt;/f:facet&gt;
              &lt;p:column selectionMode="single" style="width:16px;text-align:center"/&gt;
              &lt;p:column headerText="ID"&gt;
                  &lt;h:outputText value="#{event.id}"&gt;
                  &lt;/h:outputText&gt;
              &lt;/p:column&gt;
              &lt;p:column headerText="Date"&gt;
                  &lt;h:outputText value="#{event.date}"&gt;
                      &lt;f:convertDateTime pattern="yyyy-MM-dd" /&gt;
                  &lt;/h:outputText&gt;
              &lt;/p:column&gt;
              &lt;f:facet name="footer"&gt;
  
                  &lt;p:commandButton process="eventlist" action="#{eventBean.delete(eventBean.event)}" value="#{eventBean.event}" ajax="true" &gt;
  
                  &lt;/p:commandButton&gt;
              &lt;/f:facet&gt;
          &lt;/p:dataTable&gt;
      &lt;/h:form&gt;
  &lt;/h:body&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>EventBean.java</strong> // <em>This is my managed bean</em></p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Date;
  import java.util.List;
  import javax.annotation.ManagedBean;
  import javax.ejb.EJB;
  import javax.inject.Named;
  import javax.enterprise.context.RequestScoped;
  
  @ManagedBean
  @Named(value = "eventBean")
  @RequestScoped
  public class EventBean {
  
  @EJB
  private EventManager em;
  
  private Event event;
  
  private Event selectedEvent = new Event(); 
  
  private Date currentDate;
  
  private List&lt;Event&gt; eventlist = new ArrayList&lt;Event&gt;();
  
  
  public Date getCurrentDate() {
      if (currentDate == null) {
          currentDate = new Date();
      }
      return currentDate;
  }
  
  public EventBean() {
  }
  
  public Event getEvent() {
      if (event == null) {
          event = new Event();
      }
      return event;
  }
  
  public void setEvent(Event event) {
      this.event = event;
  }
  
  public List&lt;Event&gt; getEventlist() {
      return eventlist;
  }
  
  public void setEventlist(List&lt;Event&gt; eventlist) {
      this.eventlist = eventlist;
  }
  
  public Event getSelectedEvent() {
  
      return selectedEvent;
  }
  
  public void setSelectedEvent(Event selectedEvent) {
      this.selectedEvent = selectedEvent;
  }
  
  public String create() {
      em.save(event);
      eventlist = em.findEvents();
      return "view";
  }
  
  public String delete(Event event){  //the event object is null
      em.deleteEvent(event);
      return "index";
  }
  }
  </code></pre>
  
  <p>Briefly, what I would like to achieve is: select properly the row from the datatable and then delete it both from the datatable and database.</p>