Kush Sahu
Kush Sahu

Reputation: 399

How can I pass dynamic value for p:remoteCommand ajax call?

I have a p:dataTable which contains p:commandLink. I need to do ajax call with parameters on mouseover event. I found that commandLink cant make ajax call by mouseover event. We have to use remotecommand for this functionality.

I prefered this solution-

p:commandLink ajax events inside of a p:dataTable

Its working nice. Since its inside dataTable, here we will get multiple remoteCommand. If I want to use single remotecommand for every ajax call of command link what I have to do.

Upvotes: 1

Views: 2663

Answers (1)

partlov
partlov

Reputation: 14277

In that case you should call JavaScript function, created by p:remoteCommand with parameter which indicates you data (it can be for example primary key of your model bean or something with which you can identify object):

onmouseover="rc([{ name: 'myData', value: #{data.code} }])"

This will pass additional parameter named muData to you listener. You can obtain that parameter with this:

FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
String code = map.get("myData").toString();

See also:

Upvotes: 4

Related Questions