2014-09-25 66 views
1

我是最新的primefaces。我想要做的是填充h:outputText,但我必须使用p:poll,因为我提出了一个请求,我必须等待响应,并且可能需要一些时间才能得到答案。一个p:投票停止另一个?

<h:form id="form1"> 
    <p:poll widgetVar="headerPoll" interval="3" listener="#{bean.refreshHeader()}" update="form1" /> 
</h:form> 
<h:form id="bodyForm"> 
    <p:commandButton actionListener = "#{bean.loadBody}" ajax="false" value="load body" /> <br/><br/> 
    <h:outputText id="bodyText" escape="false" value="#{bean.body}" /> 
    <p:poll widgetVar="bodyPoll" interval="3" listener="#{bean.refreshBody()}" update="bodyText" /> 
</h:form> 

相关的豆:

public void refreshHeader() 
    { 
     if(header != null) 
     { 
      RequestContext reqCtx = RequestContext.getCurrentInstance(); 
      reqCtx.execute("headerPoll.stop();"); 
     } 
    } 

    public void refreshBody() 
    { 
     if(body != null) 
     { 
      RequestContext reqCtx = RequestContext.getCurrentInstance(); 
      reqCtx.execute("bodyPoll.stop();"); 
     } 
    } 

的问题是在refreshHeader()功能。当headerPoll.stop()得到执行时,停止第一轮和第二轮轮询。我只需要停止一个。

我该如何停止其中一项调查?

+0

您使用的是哪个版本的PF? – 2014-09-25 13:15:04

+0

你必须注意,你有一个按钮是ajax =“false”,会影响你的民意调查....我测试了你的代码,它对我来说工作得很好。 – 2014-09-25 13:27:06

+0

你可以“停止”(使渲染属性为false)停止行为。 – Cold 2014-09-25 13:37:05

回答

0

看到你已经在投票中设置了interval=3,这就是为什么两个函数并行调用的原因。尝试在不同的时间运行投票。希望它能工作:)

+0

执行第一个功能停止第二轮询。在这种情况下_refreshBody()_永远不会被调用。我试图改变时间间隔,但没有。对不起:( – cata321 2014-09-25 11:22:51