Link to home
Start Free TrialLog in
Avatar of prain
prainFlag for United States of America

asked on

How to capture the clicked row number in a p:dataTable from the backer bean?

I have tried this, But I do not get the value printed. Instead an exception. Can someone help?

<p:dataTable id="theTable"  var="theTableIterator"
    value="#{theBean.jobList}"
    selection="#{theBean.selectedRow}"
    rowIndexVar="rowIndex"
    widgetVar="datatableVar" >

    <p:column>
          <p:commandLink value="#{theTableIterator.jobName}"
                        style="#{theBean.styleString}"
                        update="theTable"
                       actionListener="#{theBean.goToClickedLink()}"
    />
   </p:column>  
        
        <p:column>
          <p:outputLabel value="#{theTableIterator.jobDescription}"
style="#{theBean.styleString}" />


public void goToClickedLink()
{      
   try {
      FacesContext context = FacesContext.getCurrentInstance();
      DataTable dt = (DataTable)
                  FacesContext.getCurrentInstance().getViewRoot().findComponent("theTable");
      
               System.out.println("Row Index : " + dt.getRowIndex());
        }
        catch (Exception e) {
                         
        }
            
      }
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of prain

ASKER

You Buty. Thanks a bunch. I do not know why I did not think in that way.
Glad it worked for you! :)