JSF,使用ajax定期刷新组件?

JSF,使用ajax定期刷新组件?,ajax,jsf,notifications,refresh,Ajax,Jsf,Notifications,Refresh,我正在开发一个JSF应用程序,我想用类似于ajax的facebook通知区行为定期刷新一个组件。 我该怎么做呢?轮询是您需要使用的 轮询组件在指定的时间间隔内进行ajax调用 例如,PrimeFacesPoll <h:form id="form"> <h:outputText id="txt_count" value="#{counterBean.count}" /> <p:poll interval="3" listener="#{counterB

我正在开发一个JSF应用程序,我想用类似于ajax的facebook通知区行为定期刷新一个组件。
我该怎么做呢?

轮询是您需要使用的

轮询组件在指定的时间间隔内进行ajax调用

例如,PrimeFacesPoll

<h:form id="form">
    <h:outputText id="txt_count" value="#{counterBean.count}" />
    <p:poll interval="3" listener="#{counterBean.increment}" update="txt_count" />
</h:form>
像这样的

<h:commandButton id="idOfButton">
    <f:ajax render="txt_count"></f:ajax>
</h:commandButton>
setInterval(function(){$("idOfButton").click()},3000);

关于计时器的更多信息在RichFaces中还有一个轮询组件。这里有一个很好的例子



根据OP的问题历史,他正在使用PrimeFaces,因此这是一个完美的选择。在未来的问题中,如果您明确提到您都使用了哪些组件库,例如PrimeFaces,这将非常有用。如果您没有提到任何东西,那么总是假设标准JSF。
<a4j:region>
      <h:form>
            <a4j:poll id="poll" interval="1000" enabled="#{userBean.pollEnabled}" reRender="poll,grid"/>
      </h:form>
</a4j:region>

<h:form>
      <h:panelGrid columns="2" width="80%" id="grid">
           <h:panelGrid columns="1">
                <h:outputText value="Polling Inactive" rendered="#{not userBean.pollEnabled}" />
                <h:outputText value="Polling Active" rendered="#{userBean.pollEnabled}" />
                <a4j:commandButton style="width:120px" id="control" value="#{userBean.pollEnabled?'Stop':'Start'} Polling" reRender="poll, grid">  
                     <a4j:actionparam name="polling" value="#{!userBean.pollEnabled}" assignTo="#{userBean.pollEnabled}"/>
                </a4j:commandButton>
          </h:panelGrid>
          <h:outputText id="serverDate" style="font-size:16px" value="Server Date: #{userBean.date}"/>
    </h:panelGrid>
</h:form>