title: Primefaces Datatable doesnt update selected rows
body: <p>I have a simple problem. I have a Primefaces Datatable. When the user clicks on a row, I would like the selected rows property in the backing bean to be updated. This can be achieved if the form that the Datatable is in is submitted, but I would like it to happen asynchronously. Ive read the various questions on here about this question, but still have not been able to find a solution.</p>
  
  <p>Here is a small example to demonstrate the issue :</p>
  
  <p>Test JSF Page:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"&gt;
  &lt;h:head&gt;
      &lt;title&gt;Facelet Title&lt;/title&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
      &lt;p:dataTable var="v" value="#{test.values}" selectionMode="multiple"
                   selection="#{test.selectedValue}" rowKey="#{v.value}" &gt;
          &lt;p:column headerText="Test"&gt;
              &lt;h:outputText value="#{v.value}" /&gt;
          &lt;/p:column&gt;
      &lt;/p:dataTable&gt;
  &lt;/h:body&gt;
  </code></pre>
  
  <p></p>
  
  <p>Backing Bean:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.ViewScoped;
  import org.primefaces.component.menuitem.MenuItem;
  import org.primefaces.component.stack.Stack;
  
  @ManagedBean
  @ViewScoped
  public class Test 
  {
  
      private Value[] selectedValues;
  
      public List&lt;Value&gt; getValues()
      {
          List&lt;Value&gt; retVal = new ArrayList&lt;Value&gt;();
          retVal.add(new Value("a"));
          retVal.add(new Value("b"));
          return retVal;
      }
  
      public Value[] getSelectedValues() {
          return selectedValues;
      }
  
      public void setSelectedValues(Value[] selectedValues) {
          this.selectedValues = selectedValues;
      }
  }
  </code></pre>
  
  <p>And a simple POJO that they use:</p>
  
  <pre><code>public class Value {
  
      private String value;
      public Value(String value)
      {
          this.value = value;
      }
  
      public String getValue()
      {
          return value;
      }
  
      public void setValue(String value)
      {
          this.value = value;
      }
  }
  </code></pre>
  
  <p>As per the responses, I have update the Datatable like so:</p>
  
  <pre><code>    &lt;p:dataTable id="dt" var="v" value="#{test.values}" selectionMode="multiple"
                   selection="#{test.selectedValues}" rowKey="#{v.value}" &gt;
          &lt;p:column headerText="Test"&gt;
              &lt;h:outputText value="#{v.value}" /&gt;
          &lt;/p:column&gt;
          &lt;p:ajax event="rowSelect"/&gt;
          &lt;p:ajax event="rowUnselect" /&gt;
      &lt;/p:dataTable&gt;
  </code></pre>
  
  <p>This however still fails to call the setter setSelectedValues(); I made them also say:</p>
  
  <pre><code>    &lt;p:ajax event="rowSelect" update="@this" /&gt;
      &lt;p:ajax event="rowUnselect" update="@this" /&gt;
  </code></pre>
  
  <p>And this only called the getter when a row was clicked. Any ideas?</p>