在jsf primefaces中停止ajax轮询?

时间:2012-08-31 10:45:25

标签: jsf primefaces

我正在使用素面3.2。 Ajax轮询没有停止,我使用停止属性来停止轮询,我试图使用getter和setter停止它来形成bean。 即使我已经使用java脚本停止但我不能。任何停止投票的解决方案?

3 个答案:

答案 0 :(得分:5)

这个代码在我的案例中就像一个魅力:

 <p:poll  interval="2" update="flightsTable" widgetVar="poll"  
         autoStart="false" listener="#{searchFlightBean.checkIfSearchCompleate}"/>

searchFlightBean中的方法:

public void checkIfSearchCompleate() {
    if(searchCompleate) {
        RequestContext reqCtx = RequestContext.getCurrentInstance();
        reqCtx.execute("poll.stop();");
    }
}

答案 1 :(得分:0)

我的解决方案:

<h:panelGroup id="chartPanel">
    <h:graphicImage value="#{resource['img:loading.gif']}" 
        rendered="#{!indexController.chartReady}"> 
        <p:poll  interval="1" update="chartPanel" autoStart="true" />
    </h:graphicImage> 
    <p:chart id="chart" type="line" model="#{indexController.chartModel}" 
        rendered="#{indexController.chartReady}" /> 
</h:panelGroup>  

当chartReady为true时,轮询停止,bean中没有进一步的代码

答案 2 :(得分:0)

<p:poll id="checkListPoll" interval="2" process="@none" 
        update="checkList" widgetVar="chkList"/>
<h:panelGroup id="checkList"> ... </h:panelGroup>

您可以从控制器使用它来停止 ajax 请求:

PrimeFaces.current().executeScript("PF('chkList').stop()"); //after Primefaces 7.0

或使用较旧的 Primefaces 版本:

import org.primefaces.context.RequestContext;
...
RequestContext.getCurrentInstance().execute("PF('chkList').stop()"); //before Primefaces 7.0