Four years have passed since the publication of this question, but the problem still remains in PrimeFaces 6.0.
I am going to publish a workaround for those who do not want (or cannot) use ViewScoped beans.
The premise is: "you cannot put any" ajaxified "element in the lazy data-bound binding of RequestScoped stuff." Never. Keep in mind that anything that challenges ajax will never work.
So, the first step is to call ajax outside of the datatable. We will do this using RemoteComand. You can put this RemoteCommand somewhere outside the DataTable (inside the form, of course)
<p:remoteCommand name="remoteCall" action="#{bean.doStuff()}"> </p:remoteCommand>
Now all we need to do is call this RemoteCommand from the DataTable. I use a link to make a javascript call, but you can use a button or whatever:
<p:column> <p:link value="#{item.id}" href="#" onclick="remoteCall([{name:'id', value:#{item.id}}])"> </p:link> </p:column>
This link makes it possible to call the javascript function "remoteCall", which will make an ajax call to "bean.doStuff ()".
Please note that the onClick event not only contains a javascript call for "remoteCall", but also contains an array of parameters with one parameter named "id" with the value "# {item.id}". This will allow RemoteCommand to send the parameter named "id" to the backup bean.
Inside the doStuff method, you will need to get the id parameter value:
public void doStuff () { String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id"); }
source share