首页 > 解决方案 > p:poll 已停止但仍会触发网络调用

问题描述

我必须使用某些条件停止并p:poll在 JSF 中启动...我可以通过将民意调查放入 panelgrid 并渲染 panelGrid 来做到这一点...我认为它可以工作,因为 pollOperationStatus 在我制作之后没有被调用panelGrid 呈现错误...当我显示它时,它也会重新启动..但是仍然有一个网络调用;这搞砸了很多事情;如何处理?

 <h:form>
    My main form
    </h:form>

        <h:form id="mypollform">

            <p:outputLabel id="currentTime" value="#{myBean.counter}" />
            <h:outputText value="#{myBean.startPoll}" id="counter11" />

            <p:panelGrid rendered="#{myBean.startPoll}">
                <p:poll interval="8" widgetVar="poller" autoStart="true"
                    listener="#{myBean.pollOperationStatus}"
                    update=":#{p:component('newServerID')},:#{p:component('mypollform')}" />
            </p:panelGrid>
        </h:form>

标签: jsfprimefacesbacking-beans

解决方案


Primefaces 7 文档说

可以使用客户端 api 启动和停止轮询;或者将布尔变量绑定到stop属性并在任意时间将其设置为 false。

在您的情况下,这将是javaScript

PF('poller').stop();或者PF('poller').start();

或者绑定一个booleanbean属性的stop属性p:poll

<p:poll stop="#{myBean.stopPoller}" interval="8" widgetVar="poller" autoStart="true"
                    listener="#{myBean.pollOperationStatus}"
                    update=":#{p:component('newServerID')} :#{p:component('mypollform')}" />

另请注意,update属性中的组件 ID 由空格分隔,而不是逗号。


推荐阅读