I have a JSF 2.2 app with primefaces 4.0. I have a page with some checklboxes. What I want to acomplish is that when I click on one checkbox an ajax request to be fired to my managed bean. That request will hit a method that will return a string. So i do no need to update an element, but to get back the string in js, because if i achieve that then I can return an JSON.
I have this piece of code :
<p:selectManyCheckbox id="queues" value="#{viewAssignUsersMB.queueIds}" layout="grid" columns="3" converter="javax.faces.Long" converterMessage="Error.">
<f:selectItems value="#{viewAssignUsersMB.queues}"
var="queue"
itemValue="#{queue.id}"
itemLabel="#{queue.application.name}"/>
<p:ajax process="@this" partialSubmit="true" event="change" listener="#{viewAssignUsersMB.xxx()}" async="true" oncomplete="handleSaveRequest(xhr, status, args)"/>
and this method in backing bean :
public void xxx(){
RequestContext.getCurrentInstance().addCallbackParam("stringToBePassed","TriluLilu");
}
and my js callback method:
function handleSaveRequest(xhr, status, args) {
alert('User with username ' +args.stringToBePassed+ ' is saved successfully');
}
My main problem now is that I do not know how to detect what checkbox was last pressed as in my backing bean I have all the checked checkboxes (#{viewAssignUsersMB.queueIds})...
Is there a better approach for that, as this is a pretty common scenario/ What is the "classic" way to achieve that ... ?