Skip to content

Mis en ligne par admin - 22 janvier 2014 - Web Applications

PrimeFaces: send data from Managed Bean to Javascript

In order to send some object data from a Managed Bean to a client-side javascript function, the following approach should be followed.

Implement a listener/action method which return the data in JSON format parsed by Gson (or any other parser:

public void actionMethod() {
    Gson gson = new Gson();

In your XHTML, any ajax component may be used to call the function, then the oncomplete function must call a function with the following parameters:

function parsingFunction(xhr, status, args) {
      var jsonObject= JSON.parse(args.mydata);
<p:ajax event="change" listener="#{myBean.actionMEthod}"             oncomplete="parsingFunction(xhr,status,args)" />

Articles similaires

Les articles suivants abordent des thèmes communs.


Partagez vos remarques.

Il n'y a pas de commentaires pour cet article.

Add a Comment

Fill in the form and submit.