无法停止 primefaces 民意调查

发布于 2024-12-16 22:00:02 字数 1095 浏览 3 评论 0原文

我正在实现一些需要公共轮询才能从服务器获取新值的对话框。 我正在尝试使用 p: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();" />

我无法理解的一件事是:当我使用 Firebug 调试中断 javascript 执行时,轮询会正确停止,但是当我不这样做时,它只是不会停止。 有人知道我该如何解决这个问题吗?

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??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯然#的苍凉 2024-12-23 22:00:02

我对“民意调查”组件也有类似的问题(谷歌将我发送到这里)。据我所知,您的标记有两个问题。我使用的是 Primefaces 3.0M4

问题 1

使用 将创建一个可使用 window.myPoll 访问的 javascript 对象。如果包含的表单被重新呈现(请参阅“更新”属性),则此属性将被覆盖。问题是在后台使用了“window.setInterval”。如果轮询器在被替换之前没有停止,则该间隔将丢失。

解决方案:

  1. 您可以创建一个仅包含 poll 组件的顶级
  2. onclick="pollQtdDisponivelCarregamento.start(); return false;" 阻止将表单发送到服务器。 (我怀疑这是你的意图)

问题 2

poll.start() 不检查它是否已经在运行。调用它两次将导致安排另一个间隔。第一个的 id 丢失了,但它仍然向您的服务器发送请求。尝试快速单击“第一个对话框”中的按钮。

解决方案:

首先调用poll.isActive()检查它是否已经在运行。

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.

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:

  1. You may create a top-level <form> containing the poll component only.
  2. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文