I'm implementing some dialogs that need a mon 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:mandButton 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:mandButton 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'm implementing some dialogs that need a mon 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:mandButton 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:mandButton 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??
Share Improve this question edited Apr 24, 2019 at 14:48 Alec 9,6338 gold badges44 silver badges70 bronze badges asked Nov 18, 2011 at 12:35 brevleqbrevleq 2,14110 gold badges55 silver badges99 bronze badges1 Answer
Reset to default 6I had similar problems with the 'poll' ponent (google sent me here). As far as I can tell there are two problems with your markup. I was using Primefaces 3.0M4.
Problem 1
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.
Solution:
- You may create a top-level
<form>
containing the poll ponent only. onclick="pollQtdDisponivelCarregamento.start(); return false;"
prevents the form from being sent to the server. (I doubt this is your intention)
Problem 2
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.
Solution:
Check if it's already running by calling poll.isActive()
first.