title: Primefaces Datatable RowSelect Event
body: <p>I have the following in my xhtml</p>
  
  <pre><code>                &lt;h:form id="clientTableForm" prependId="false"&gt;
                      &lt;p:dataTable id="clientTable" widgetVar="clientTableVar"
                          var="client" value="#{resendEmailController.lazyDataModel}"
                          paginator="true" rows="15"
                          paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink}  {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport}"
                          rowsPerPageTemplate="5,10,15,20,25,50,75,100"
                          paginatorPosition="bottom" pageLinks="5" lazy="true"
                          sortBy="#{client.cclnCode}" sortOrder="ascending"
                          selection="#{resendEmailController.selectedClient}"
                          selectionMode="single" filterDelay="500" scrollable="true"
                          scrollHeight="380"&gt;
  
                          &lt;p:ajax event="rowSelect"
                              listener="#{resendEmailController.changeClient}"
                              update="_accountTableForm_accountTable" /&gt;
  
  
  
                          &lt;p:column id="cclnCodeColumn" headerText="Client Code"
                              style="width:25%;" sortBy="#{client.cclnCode}"
                              filterBy="#{client.cclnCode}" filterMaxLength="10"&gt;
                              &lt;h:outputText value="#{client.cclnCode}"
                                  converter="#{trimStringConverter}" /&gt;
                          &lt;/p:column&gt;
  
                          &lt;p:column id="cclnNamenColumn" headerText="Client Name"
                              style="width:75%" sortBy="#{client.cclnName}"
                              filterBy="#{client.cclnName}" filterMaxLength="50"&gt;
                              &lt;h:outputText value="#{client.cclnName}"
                                  converter="#{trimStringConverter}" /&gt;
                          &lt;/p:column&gt;
                      &lt;/p:dataTable&gt;
                  &lt;/h:form&gt;
              &lt;/p:layoutUnit&gt;
  
  &lt;script type="text/javascript"&gt;
  
          $(document).ready(function()
          {
              autoSelectClient();
          });
  
  
          function autoSelectClient()
          {
              if (clientTableVar.isEmpty() == false)
              {
                  clientTableVar.selectRow(1, false);
              }
          }
  
          &lt;/script&gt;
  </code></pre>
  
  <p>And I have this in my backing bean</p>
  
  <pre><code>    public void changeClient(SelectEvent selectEvent)
  {
      ResendEmailClient client = (ResendEmailClient) selectEvent.getObject();
  
      selectedClient = client;
  
      String cclnCode = client.getCclnCode();
  
      selectedAccounts = getService().listAccounts(cclnCode);
  }
  </code></pre>
  
  <p>I would just like to ask why the "selectedClient" variable in the backing bean is NULL when executed by the "autoSelectClient();". But if I clicked the rows the "selectedClient" is already set. </p>
  
  <p>As you can see in my backing bean I can get the value I want by getting the object inside the SelectEvent but I just want to know what is the cause of the difference.</p>
  
  <p>Also if possible can any also suggest how to replicate the emulate the second scenario so that the "selectedClient" is already set before the "changeClient()" is invoked.</p>
  
  <p>Using 
  JSF 2.1
  PrimeFaces 3.5
  Mojarra 2.1</p>