?
Solved

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

Posted on 2014-04-07
3
Medium Priority
?
2,177 Views
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"
    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) {
                         
        }
            
      }
0
Comment
Question by:prain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 36

Accepted Solution

by:
mccarl earned 1000 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}"
                        style="#{theBean.styleString}"
                        update="theTable"
                       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

0
 

Author Closing Comment

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

Expert Comment

by:mccarl
ID: 39990506
Glad it worked for you! :)
0

Featured Post

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

801 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