简体   繁体   English

JSF呈现来自托管bean的数据表内容吗?

[英]JSF render data table content from managed-bean?

I'm using Richfaces to develop some web pages, with a datatable I try to display some data information from remote server. 我正在使用Richfaces开发一些网页,并使用一个数据表尝试显示来自远程服务器的一些数据信息。 But its quite slow to load all data in one time, so I use a cache to store data, Firstly my cache is empty and data table is empty. 但是一次加载所有数据的速度很慢,因此我使用缓存来存储数据,首先,我的缓存为空,数据表为空。

The ideal goal is loading one row from server(let say 1mins for each row) and store into my cache, then append into data table's end, my question is how can I render the content of data table from managedbean once I retrieve some new data into cache? 理想的目标是从服务器加载一行(每行说1分钟)并存储到我的缓存中,然后追加到数据表的末尾,我的问题是,一旦检索到一些新数据,如何从托管bean呈现数据表的内容进入缓存?

I also use a timer to update the cache values from server during a fixed period (1hour), that means later, new data could be added into cache, and old data could be removed from cache, that all depend on server's latest data. 我还使用计时器在固定的时间段(1小时)内更新服务器的缓存值,这意味着以后可以将新数据添加到缓存中,并可以从缓存中删除旧数据,这都取决于服务器的最新数据。 same question when I get a fresh cache and need rerender data table content according to cache values. 当我得到一个新的缓存并需要根据缓存值重新呈现数据表内容时,同样的问题。

Thanks, 谢谢,

The most easy way to do this is rerendering your table. 最简单的方法是重新渲染表。 There are two approaches to do this using RichFaces library: 有两种使用RichFaces库执行此操作的方法:

Client Side 客户端

The a4j:poll component defines a way to periodically poll a server in order to trigger state changes, or update parts of your page. a4j:poll组件定义了一种定期轮询服务器以触发状态更改或更新页面部分的方法。 It uses a timer to trigger each N milliseconds. 它使用计时器每N毫秒触发一次。

You can use it to check your cache data on your server and then rerender your table. 您可以使用它来检查服务器上的缓存数据,然后重新呈现表。

<!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>

More information on RichFaces a4j:poll . 有关RichFaces a4j:poll的更多信息。

Server Side 服务器端

The a4j:push works as a consumer/producer architecture, which uses no timer, instead it uses a message that will instruct the client to re-render part of the page. a4j:push用作消费者/生产者体系结构,它不使用任何计时器,而是使用一条消息来指示客户端重新呈现页面的一部分。

Using this component you will be able to have an impact on the client side (rerender HTML) from the java methods in your ManagedBean. 使用此组件,您将能够从ManagedBean中的java方法对客户端(渲染HTML)产生影响。 Maybe the problem here will be to communicate your current cache architecture with your JSF Managed Bean . 也许这里的问题是将当前的缓存体系结构JSF托管Bean进行通信。

More information on RichFaces a4j:push . 有关RichFaces a4j:push的更多信息。

Regards, 问候,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM