R
The solution was:Use p:poll of primefaces or a p:remoteCommand to invoke one action Backing Bean.<p:poll autoStart="true" listener="#{mBeanTesteIsolado.teste}"
oncomplete="handleComplete(xhr, status, args)" interval="3" />
Or with p:remoteCommand:<p:remoteCommand name="atualizarUI" actionListener="#{mBeanTesteIsolado.teste}" oncomplete="handleComplete(xhr, status, args)" />
In the case of p:remoteCommand, using a setInterval to call at regular intervals:setInterval(function() { atualizarUI(); }, 3000);
With attention to the function assigned to oncomplete, in relation to its signature, which must accept 3 arguments (xhr, status, args)At Backing Bean, use the RequestContext.addCallbackParam to return data to the JavaScript function used in oncomplete, so much p:poll the p:remoteCommand.Setting the Backing Bean return to the Javascript function:Managed Beanpublic void teste() {
// Processamento necessário
RequestContext context = RequestContext.getInstance();
// Adiciona as variáveis para o JS (variável args da assinatura)
context.addCallbackParam("nomeDoAtributo", "valor");
}
Treating the return in JavaScript:JSfunction handleComplete(xhr, status, args) {
var nomeDoAtributo = args.nomeDoAtributo;
// Atualizar UI
gauge.setValueAnimated(nomeDoAtributo);
}