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

Posted on 2014-04-07
Last Modified: 2014-04-09
I have tried this, But I do not get the value printed. Instead an exception. Can someone help?

<p:dataTable id="theTable"  var="theTableIterator"
    widgetVar="datatableVar" >

          <p:commandLink value="#{theTableIterator.jobName}"
          <p:outputLabel value="#{theTableIterator.jobDescription}"
style="#{theBean.styleString}" />

public void goToClickedLink()
   try {
      FacesContext context = FacesContext.getCurrentInstance();
      DataTable dt = (DataTable)
               System.out.println("Row Index : " + dt.getRowIndex());
        catch (Exception e) {
Question by:prain
  • 2
LVL 35

Accepted Solution

mccarl earned 250 total points
ID: 39987701
Again, I don't know too much about JSF/Primefaces but since no one else has commented with a solution, I'll give what I think *MAY* work...

Try this, in your p:commandLink can you pass variables as arguments, where "rowIndex" is what you defined in your p:dataTable as the rowIndexVar, ie...
          <p:commandLink value="#{theTableIterator.jobName}"
                       actionListener="#{theBean.goToClickedLink(rowIndex)}"  />

Open in new window

And then in your Java code, you might be able to define the ActionListener to accept that variable...
public void goToClickedLink(int rowIndex)
    // do something with "rowIndex"

Open in new window


Author Closing Comment

ID: 39988870
You Buty. Thanks a bunch. I do not know why I did not think in that way.
LVL 35

Expert Comment

ID: 39990506
Glad it worked for you! :)

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
NotAlone Challenge 20 79
thymeleaf natural templating vs JSP 2 66
stackato and cloud 4 68
more than one jdk and one jre 1 31
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now