页面加载后将列表绑定到数据表(不是延迟加载)

发布于 2024-10-12 00:08:22 字数 462 浏览 1 评论 0原文

我们的页面有一个数据表,显示来自网络服务的记录。 Web 服务查询数据库,查询可能需要 10 秒到 100 秒。

我最初在支持 bean 构造函数中加载绑定到数据表的数组列表:

private ArrayList myList;
public MyBean
{
     myList = WebServices.getList();
}

在这种情况下,整个页面仅在 Web 服务返回所有数据后才开始呈现。

我应该在哪里调用 web 服务(即,执行 myList = WebServices.getList(); )以便并行加载页面的其余部分,并在数据表中显示进度条或其他内容网络服务运行吗?

我想我关于 JSF/IceFaces 生命周期的概念还不清楚...

另外,这与延迟加载无关,因为为此我们也必须在数据库查询中实现分页。

谢谢!

Our page has a datatable which shows records from a web service. The web service queries a database, and the query can take from 10 secs to 100 secs.

I was initially loading the arraylist binded to the datatable in the backing bean constructor:

private ArrayList myList;
public MyBean
{
     myList = WebServices.getList();
}

In this scenario, the entire page starts to render only after the web service returns all data.

Where should I call the webservice (i.e., do myList = WebServices.getList(); ) in order to have the rest of the page load in parallel, and show a progress bar or something in the datatable while the webservice runs?

I guess my concepts about the JSF/IceFaces lifecycle are not clear...

Also, this is not about lazy loading, because for that we would have to implement pagination in our datatabase query, too.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木槿暧夏七纪年 2024-10-19 00:08:22

我找到了使用线程的解决方法。

public class MyBean
{
    private ArrayList myList;
    private PersistentFacesState state;

    public MyBean
    {
        state = PersistentFacesState.getInstance();
        myList = new ArrayList();
        new Thread(new RunService()).start();
    }

    public class RunService implements Runnable
    {
        public void run()
        {
            try
            {
                list = WebServices.getList();
                state.executeAndRender(); //Need to do this to update view

            }
            catch(Exception e)
            {

            }
        }

    }
}

最初我不知道 PersistentFacesStateexecuteAndRender(); ,因此即使线程会更新数组列表,视图也不会刷新。这是因为 JSF/IceFaces 生命周期已经结束。

保留视图然后重新渲染它也解决了这个问题。

希望这个解决方案可以帮助某人。

I found a work around using Threads.

public class MyBean
{
    private ArrayList myList;
    private PersistentFacesState state;

    public MyBean
    {
        state = PersistentFacesState.getInstance();
        myList = new ArrayList();
        new Thread(new RunService()).start();
    }

    public class RunService implements Runnable
    {
        public void run()
        {
            try
            {
                list = WebServices.getList();
                state.executeAndRender(); //Need to do this to update view

            }
            catch(Exception e)
            {

            }
        }

    }
}

Initally I was not aware of the PersistentFacesState and executeAndRender(); , so even though the thread would update the array list, the view wasn't being refreshed. This was because the JSF/IceFaces lifecycle had already ended.

Persisting the view and then re-rendering it solved this problem, too.

Hope this solution helps someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文