最简单的方法来做到这一点是重新描绘你的表。有做到这一点使用RichFaces的库两种方法:
客户端
的A4J:投票组件定义了一种方法,以便触发状态变化,或更新部分定期轮询服务器的页。它使用一个定时器来触发每个N毫秒。
你可以用它来检查你的缓存服务器上数据,然后重新呈现你的表。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:form>
<a4j:poll id="poll" interval="2000" enabled="#{pollBean.pollEnabled}" render="poll,grid" />
</h:form>
<h:form>
<h:panelGrid columns="2" width="80%" id="grid">
<h:panelGrid columns="1">
<h:outputText value="Polling Inactive" rendered="#{not pollBean.pollEnabled}"></h:outputText>
<h:outputText value="Polling Active" rendered="#{pollBean.pollEnabled}"></h:outputText>
<a4j:commandButton style="width:120px" id="control" value="#{pollBean.pollEnabled?'Stop':'Start'} Polling"
render="poll, grid">
<a4j:param name="polling" value="#{!pollBean.pollEnabled}" assignTo="#{pollBean.pollEnabled}" />
</a4j:commandButton>
</h:panelGrid>
<h:outputText id="serverDate" style="font-size:16px" value="Server Date: #{pollBean.date}" />
</h:panelGrid>
</h:form>
</ui:composition>
有关RichFaces a4j:poll的更多信息。
服务器端
的A4J:推作品作为一个生产者/消费者架构,它不使用计时器,而是使用一个消息,将指示客户端重新渲染的部分页。
使用此组件,您将能够从ManagedBean中的java方法对客户端(重新渲染HTML)产生影响。也许这里的问题是将您当前的缓存架构与您的JSF Managed Bean进行通信。
有关RichFaces a4j:push的更多信息:
Regards,
谢谢,我看到了RichFaces Showcase上的轮询函数,但我真的希望同时更新数据表内容。由于下面的复查周期为1小时+,如果我使用一个小的间隔来检查缓存值,大部分时间它将不会得到任何添加/删除,因为缓存未更新,如果我使用较大的时间间隔,则用户将看不到“实时“缓存值。我不确定在JSF中是否有可以重新呈现托管bean内容的东西。 – user1684651 2013-05-14 09:08:07
在这种情况下,您需要相反的组件:** a4j:push **其中_消息指示客户端重新渲染页面的一部分。 [Checkit](http://showcase.richfaces.org/richfaces/component-sample.jsf?demo = push&sample = pushTopicsContext&skin = blueSky) – 2013-05-14 09:18:50
是轮询/推送消息相关吗?它似乎仍然使用固定的时间间隔来为我工作,就像一个计时器任务。 – user1684651 2013-05-14 11:16:46