8

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
4Money
  • 179
  • 1
  • 1
  • 10
  • I think what he is looking for is: http://stackoverflow.com/questions/14633008/jsf-2-datatable-row-index-without-datamodel in case of plain JSF. – JanM Nov 10 '13 at 09:35

2 Answers2

21

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>
Kishor Prakash
  • 8,011
  • 12
  • 61
  • 92
  • 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) – Hari Ram Aug 26 '16 at 12:25
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");
Rohan Khude
  • 4,455
  • 5
  • 49
  • 47
sijo jose
  • 1,887
  • 1
  • 10
  • 8