title: Set selected row from backing bean in primefaces datatable
body: <p>I am using primefaces datatable with clickable rows and I need to find way how to set selected row from backing bean.</p>
  
  <p>There is my datatable definition:</p>
  
  <pre><code>&lt;p:dataTable id="cablePathTable" var="cablePath" value="#{commonTableBean.cableLazyModel}" rows="100"
           selectionMode="single" selection="#{commonTableBean.selectedCablePathTblRow}" 
           rowIndexVar="rowIndex"  widgetVar="datatableVar"
           emptyMessage="---"&gt;  
  &lt;p:ajax event="rowSelect" process="@this" update=":form:portFieldset" /&gt;
  
  &lt;p:column headerText="No"&gt;  
      &lt;h:outputText value="#{cablePath.column1}" /&gt;  
  &lt;/p:column&gt;
  &lt;p:column headerText="Port A"&gt;  
      &lt;h:outputText value="#{cablePath.column4}" /&gt;  
  &lt;/p:column&gt;
  &lt;p:column headerText="Port B"&gt;  
      &lt;h:outputText value="#{cablePath.column5}" /&gt;  
  &lt;/p:column&gt;
  </code></pre>
  
  <p></p>
  
  <p>I have tried following approach, but with no success.
  In backing bean I have added method:</p>
  
  <pre><code>public void test(){
      DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("form:cablePathTable");
      dataTable.setRowIndex(2);
  }
  </code></pre>
  
  <p>And I have added test butoon to the XHTML page:</p>
  
  <pre><code>&lt;p:commandButton process="@this" update=":form:cablePathTable" value="set2row" action="commonTableBean.test"/&gt;
  </code></pre>
  
  <p>But nothig is changed on the datatable, selection didn't change...</p>
  
  <p>Please any ideas how to solve this problem?</p>