title: Rich faces and dataTable
body: <p>I have the question regarding rich faces and beans.
  I have a jsp page that is using richfaces and inside it I have the: rich:extendedDatatable component, that takes data from my MainBean as ArrayList (this bean queries the mySQL and puts results to the ArrayList that populates the dataTable later on). There are 4 columns in datatable, first 3 are h:outputLabels and the last one is checkbox. Now I have a question: how can I get information from selected row ? I mean, when user clicks checkbox, I want to take the id/name or whatever that is associated to this particular row, then when user clicks on Apply changed a4j: button I will update the database and when user logs in back again he will see updated info: e.g. checkbox is selected/not selected now because the user checked that.
  I believe that is a simple query for someone who worked with it. For me ex. flash developer it would be easy in as3, but here I didnt find the solution yet, please help.</p>
  
  <p><strong>Update</strong>: </p>
  
  <p>Let me explain and publish the code. When user logs in, then I make a query to database where I have 2 tables. First one is with "activities" (act_id, name, description, date) and second one is called "common" (that stores user_id and act_id in it). My idea is to store data that tells me, which user is assigned to each activity. In this case, e.g. user with id 1, is using activity 1 2 and 3, and user with id 2 is using activity 2 and 4, then when query from database returns a result, I simply create an ArrayList with apropriate data. So when user clicks on checkbox, then insert query is made, when user unselect the checkbox, then delete query to database is made (based on user id and act_id) here is the code for query method, first I must get user_id:</p>
  
  <pre><code>public String login() {
      Statement stmt2 = null;
      Statement stmt3 = null;
      ResultSet rs = null;
      ResultSet rs2 = null;
      ResultSet rs3 = null;
      String sql = "SELECT * from user";
      String sql2 = "SELECT * from activities";
      try {
        conn = DriverManager.getConnection(jdbcUrl, user, pass);
        stmt = conn.createStatement();
        stmt2 = conn.createStatement();
        boolean selected = true;
  
        rs = stmt.executeQuery(sql);
        rs2 = stmt2.executeQuery(sql2);
         while(rs.next()) {
          if (username != null &amp;&amp; password != null) {
            if (rs.getString("username").equals(username)
                &amp;&amp; rs.getString("password").equals(password)) {
              id = rs.getString("user_id");
              stmt3 = conn.createStatement();
              while(rs2.next()){
                selected = false;
                String aid = rs2.getString("act_id");
                String name = rs2.getString("name");
                String desc = rs2.getString("desc");
                String date = rs2.getString("date");
                String sql3 = "SELECT * from common where uid="+id+"";
                rs3 = stmt3.executeQuery(sql3);
                while(rs3.next()) {
                   if(rs3.getString("aid").equals(aid)){
                     activities.add(new Activity(name, desc, date, true));
                     selected = true;
                   }
  
                }
                if(!selected)
                  activities.add(new Activity(name, desc, date, false));
              }
              return "success";
            }
          }
      } 
      }catch (SQLException sqle) {
        sqle.printStackTrace();
      } finally {
        try {
          rs.close();
          stmt.close();
          conn.close();
        } catch (SQLException e) {
        }
      }
      return "failure";
    }
  </code></pre>
  
  <p>And rich faces view:</p>
  
  <pre><code>&lt;a4j:form&gt;
  &lt;rich:extendedDataTable id="activities" value="#{mainBean.activities}" var="acts" sortMode="single"&gt;
          &lt;rich:column label="Name" sortable="true" sortBy="#{acts.name}"&gt;
          &lt;f:facet name="header"&gt; 
                   &lt;h:outputText value="Name" /&gt;
            &lt;/f:facet&gt;
          &lt;h:outputLabel value="#{acts.name}" /&gt;
          &lt;/rich:column&gt;
          &lt;rich:column label="Description" sortable="true" sortBy="#{acts.description}"&gt;
          &lt;f:facet name="header"&gt; 
                   &lt;h:outputText value="Description" /&gt;
            &lt;/f:facet&gt;
          &lt;h:outputLabel value="#{acts.description}" /&gt;
          &lt;/rich:column&gt;
          &lt;rich:column label="Date" sortable="true" sortBy="#{acts.date}"&gt;
          &lt;f:facet name="header"&gt; 
                   &lt;h:outputText value="Date" /&gt;
            &lt;/f:facet&gt;
          &lt;h:outputLabel value="#{acts.date}" /&gt;
          &lt;/rich:column&gt;  
          &lt;rich:column label="Selected" sortable="true" sortBy="#{acts.selected}"&gt;
          &lt;f:facet name="header"&gt; 
                   &lt;h:outputText value="Selected" /&gt;
            &lt;/f:facet&gt;
          &lt;h:selectBooleanCheckbox value="#{acts.selected}" /&gt;
          &lt;/rich:column&gt;
          &lt;/rich:extendedDataTable&gt;
          &lt;h:commandButton value="Apply changes" action="#{mainBean.addActivity}" /&gt;
          &lt;/a4j:form&gt;
  </code></pre>