Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get id from current row dataTable to link JSF Primefaces Java [duplicate]

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.

like image 261
4Money Avatar asked Nov 09 '13 16:11

4Money


2 Answers

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>
like image 156
Kishor Prakash Avatar answered Nov 09 '22 03:11

Kishor Prakash


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");
like image 43
sijo jose Avatar answered Nov 09 '22 02:11

sijo jose