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="#{rotaEntregaBean.gerarMapa()}"
I execute the function in the Bean (getting values in the database) and then, aqui:oncomplete="initMap(xhr, status, args)"
I execute the JS function.
Button
<p:commandButton id="btnMapa" value="Gerar Rota" icon="ui-icon-pin-s"
actionListener="#{rotaEntregaBean.gerarMapa()}"
style="float:right" oncomplete="initMap(xhr, status, args)"/>
Bean
ButI'mwantingtodothiswithouthavingtoclickthebuttonassoonasIloadthepage.InmypageIalreadystartaBeanmethodasshownintheimagebelow,butIdonotknowhowtocalltheJSfunctionwithparameter.
CallingBeanmethodassoonasthepageloads:
<f:metadata><o:viewParamname="entrega_id" value="#{rotaEntregaBean.id_entrega}" />
<f:viewAction action="#{rotaEntregaBean.inicializar}" />
</f:metadata>
JS Function
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,
});
}
...
}