lundi 30 octobre 2017

How to call a JS function by Bean JSF passing parameter as soon as the page loads?

I have to call a function in my JS by passing a vector as a parameter when the page loads.

I can do this using a p: commandButton, where here:

 actionListener = "# {routeEnterBean.GetMap ()}"

I run the function in the Bean (getting values in the database) and then, here:

 oncomplete = "initMap (xhr , status, args) "

Thus, the JS function is executed

Code Bean:

public void gerarMapa() {   
        RequestContext context = RequestContext.getCurrentInstance();
        context.addCallbackParam("coord", new 
          org.primefaces.json.JSONArray(coordenadas));
    }

Function JS

function initMap(xhr, status, args) {  
    var qtd_entregas = args.coord.length;
    for (var i = 0; i < args.coord.length; i++) {
        waypts.push({
            location : args.coord[i].latitude + ', ' + args.coord[i].longitude,
            stopover : true,
        });
    }
}

But I'm wanting to do this without having to click the button as soon as I load the page.

I know that it is possible to execute a function using this command:

RequestContext.getCurrentInstance().execute("testeJS();");

But I do not know how to pass a vector as a parameter




Aucun commentaire:

Enregistrer un commentaire