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)
纯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计时事件的更多信息
在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)
| 归档时间: |
|
| 查看次数: |
32342 次 |
| 最近记录: |