Get id from current row dataTable to link JSF Primefaces Java

32,985

Solution 1

You can use p:dataTable's rowIndexVar attribute.

Name of the iterator to refer each row index

Whose iterator name can be used in EL to get the Row Id

For Example: if rowIndexVar="myId" then you can access each row Index using that iterator name in EL using #{myID}.

Example:

<p:dataTable rowIndexVar="rowId" value="..." var="...">
    <p:column>
       <h:commandLink action="#{...}">
         <f:param name="id" value="#{rowId}" />
       </h:commandLink>
    </p:column>
</p:dataTable>

Solution 2

Get id in bean

map<String,String> par_map = new HashMap<String,String>(); par_map=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

String id=par_map.get("id");
Share:
32,985
4Money
Author by

4Money

Updated on July 09, 2022

Comments

  • 4Money
    4Money almost 2 years

    How can i get Id of current Row p:dataTable primefaces to my link where is used this Id? Describe it (sorry for my English). My dataTable looks like on this picture:
    http://www.image-share.com/igif-2333-105.html
    When i click the button i want to get Id of row where is this button, for example row 1 have id 1, so when button 1 is clicked i must get ID = 1. Show how looks my link where need id:
    http://'serverAddress'/myApplication/PDF?type=document&id="+id"
    Variable id have type int and getters, setters in entity and bean. Button in JSF looks like below:
    h:commandButton value="Print" action="#{printBean.print()}"/>
    Method 'Print' initiate my link. Any ideas how to do this? Thanks for help.

  • Hari Ram
    Hari Ram over 7 years
    And how would I use the selected rowId in my bean function? I mean, I need a variable whose value is one when I click the button in first row (Or any other technique which would let me know the selected row in my table)