title: Select a row in jsf datatable
body: <p>Here is my table:</p>
  
  <pre><code>&lt;h:dataTable var="book" value="#{ordersBean.userOrders}"
               binding="#{ordersBean.htmlDataTable}"&gt;
      &lt;h:column&gt;
          &lt;f:facet name="header"&gt;order ID&lt;/f:facet&gt;
          &lt;h:outputText value="#{book[0]}"/&gt;
      &lt;/h:column&gt;
      &lt;h:column&gt;
          &lt;f:facet name="header"&gt;Book Title&lt;/f:facet&gt;
          &lt;h:outputText value="#{book[1]}"/&gt;
      &lt;/h:column&gt;
      &lt;h:column&gt;
          &lt;f:facet name="header"&gt;Cost&lt;/f:facet&gt;
          &lt;h:outputText value="#{book[2]}"/&gt;
      &lt;/h:column&gt;
      &lt;h:column&gt;
          &lt;f:facet name="header"&gt;Remove Order&lt;/f:facet&gt;
          &lt;h:commandButton action="#{ordersBean.deleteOrder}" image="resources/images/del.gif"/&gt;
      &lt;/h:column&gt;
  &lt;/h:dataTable&gt;
  </code></pre>
  
  <p>I need to get <code>Order ID</code> of which row that the user clicks on it's <code>Remove Order</code> icon and then remove that order from <code>DAO</code>.</p>
  
  <p>Here is the <code>deleteOrder()</code>:</p>
  
  <pre><code>@ManagedBean
  @SessionScoped
  public class OrdersBean {
  
  private List&lt;Book&gt; userOrders = new ArrayList&lt;Book&gt;();
  private HtmlDataTable htmlDataTable;
  
  @Transactional
  public void deleteOrder() {
      Book selectedBook = (Book) htmlDataTable.getRowData(); // class cast exception (168)
  }
  
  //For populating table
  @Transactional
  public List&lt;Book&gt; userAllOrders() {
      userOrders = bookDao.getTitleCostQty(String.valueOf(currentUser.getId())).list();
      return userOrders;
  }
  
  public HtmlDataTable getHtmlDataTable() {
      return htmlDataTable;
  }
  
  public void setHtmlDataTable(HtmlDataTable htmlDataTable) {
      this.htmlDataTable = htmlDataTable;
  }
  //getter/setters
  </code></pre>
  
  <p>But i get this error:</p>
  
  <pre><code>javax.servlet.ServletException: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.obs.model.Book
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  
  javax.faces.el.EvaluationException: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.obs.model.Book
      javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
      com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
  
  java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.obs.model.Book
      com.obs.bean.OrdersBean.deleteOrder(OrdersBean.java:168)
  </code></pre>