title: Select Row in primefaces data table
body: <p>I have this table:</p>
  
  <p><img src="https://i.stack.imgur.com/XnrYP.png" alt="enter image description here"></p>
  
  <pre><code>&lt;h:form&gt;
      &lt;p:dataTable id="books" value="#{ordersBean.userOrders}" var="book" selection="#{ordersBean.selectedBook}"&gt;
          &lt;p:column&gt;
              &lt;f:facet name="header"&gt;Order ID&lt;/f:facet&gt;
              &lt;h:outputText value="#{book[0]}"/&gt;
          &lt;/p:column&gt;
          &lt;p:column&gt;
              &lt;f:facet name="header"&gt;Title&lt;/f:facet&gt;
              &lt;h:outputText value="#{book[1]}"/&gt;
          &lt;/p:column&gt;
          &lt;p:column&gt;
              &lt;f:facet name="header"&gt;&lt;/f:facet&gt;
              &lt;p:commandButton id="selectRowBtn" value="select" action="#{ordersBean.showSelectedBook}"/&gt;
          &lt;/p:column&gt;
      &lt;/p:dataTable&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>I want when i click on each <code>select</code> button, it's row information assigned to <code>selectedBook</code> property and displays it in <code>showSelectedBook()</code> method:</p>
  
  <p>Here is the <code>ordersBean</code>:</p>
  
  <pre><code>private Book selectedBook = new Book();
  
  public Book getSelectedBook() {
      return selectedBook;
  }
  
  public void setSelectedBook(Book selectedBook) {
      this.selectedBook = selectedBook;
  }
  
  public void showSelectedBook() {
      System.out.println("In selected Book(), book: " + getSelectedBook());
  }
  </code></pre>
  
  <p>But result is this:</p>
  
  <p><code>In selected Book(), book: null</code></p>