I'm implementing some dialogs that need a common poll to get fresh values from the server. I'm trying use p:poll, but unfortunately I cant stop it. I start the poll when a user clicks on a button in one dialog, and try stop that when a user clicks a button in a child dialog. This is the code I`m using to start and stop the poll:
firstDialog:
<p:poll autoStart="false" widgetVar="pollQtdDisponivelCarregamento" immediate="true"
update="labelQuantidadeDisponivelCarregamento labelQuantidadeDisponivelItem"
listener="#{atualizadorQuantidadeDisponivelProduto.atualizarQuantidadeDisponivel(modeloPopupCarregarProduto.produtoSelecionado)}" />
<p:commandButton action="#{controladorPopupCarregarProduto.abrir}"
value="#{vendaMsg['popup.pre_venda.botao.adicionar_produto']}"
title="#{vendaMsg['popup.pre_venda.botao.adicionar_produto.descricao']}"
update="@form" onclick="pollQtdDisponivelCarregamento.start()" />
childDialog:
<p:commandButton value="OK" style="float:right" immediate="true"
action="#{controladorPopup.fechar}" update="@form"
onsuccess="pollQtdDisponivelCarregamento.stop();" />
One thing I can't understand is: when I break javascript execution using Firebug debug, the poll stops correctly, but when I don't do this, it just don't stop. Someone knows how can I solve this??
I had similar problems with the 'poll' component (google sent me here). As far as I can tell there are two problems with your markup. I was using Primefaces 3.0M4.
Using <p:poll clientVar="myPoll"/>
will create a javascript object accessible using window.myPoll
. If the containing form is rerendered (see your 'update' attribute) this property is overwritten. The problem is that uses 'window.setInterval' under the hood. If the poller isn't stopped before beeing replaced this interval is lost.
<form>
containing the poll component only.onclick="pollQtdDisponivelCarregamento.start(); return false;"
prevents the form from being sent to the server. (I doubt this is your intention)poll.start()
doesn't check if it's already running. Invoking it twice will cause another interval to be scheduled. The first one's id is lost, but it's still there sending requests to your server. Try clicking the button in 'first dialog' rapidly.
Check if it's already running by calling poll.isActive()
first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With