JSF,定期刷新ajax组件?

Pot*_*nos 15 ajax jsf notifications refresh

我正在研究应用程序JSF,我想定期刷新一个带有ajax的组件,如facebook通知区域行为.我怎样才能做到这一点?

Dan*_*iel 31

民意调查是您需要使用的

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

例如Primefaces民意调查

<h:form id="form">
    <h:outputText id="txt_count" value="#{counterBean.count}" />
    <p:poll interval="3" listener="#{counterBean.increment}" update="txt_count" />
</h:form>
Run Code Online (Sandbox Code Playgroud)

链接展示Primefaces Ajax民意调查

纯JSF方法将使用将调用周期性的js计时器 document.getElementById('someFormId:idOfButton').click();

或jquery $("#someFormId\\:idOfButton").click();

按钮看起来像这样

<h:commandButton id="idOfButton">
    <f:ajax render="txt_count"></f:ajax>
</h:commandButton>
Run Code Online (Sandbox Code Playgroud)

这样的事情

setInterval(function(){$("idOfButton").click()},3000);
Run Code Online (Sandbox Code Playgroud)

有关计时器JavaScript计时事件的更多信息

  • 基于OP的问题历史,他正在使用PrimeFaces,因此这是一个完美的套装. (2认同)

sim*_*eer 5

在RichFaces中也有一个民意调查组件.这是他们提供的一个很好的例子

<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>
Run Code Online (Sandbox Code Playgroud)