Primefaces惰性Datascroller调用两次加载 [英] Primefaces lazy datascroller calling load twice

查看:110
本文介绍了Primefaces惰性Datascroller调用两次加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Datascroller与LazyDataModel结合使用,并且懒惰数据模型的load方法被调用两次.

I'm trying to use a Datascroller with a LazyDataModel and the load method from lazy data model is getting called twice.

Appart认为多次调用装入方法(可能会执行昂贵的服务器/数据库往返)不是那么好,因为我的惰性数据模型不是幂等的(意味着在同一窗口上两次连续调用该模型) /页面大小返回不同的结果)被两次调用的事实意味着:显示的结果不正确.

Appart from thinking that it is not so good to call the load method multiple times (that may perform costly server/DB roundtrips), since my lazy data model not idempotent (meaning, two consecutive calls to the model on the same window/page size returns different outcomes) the fact that it's being called twice means: the presented results are not correct.

两次调用datascroller中的load方法是否正常? 如果是这样,建议采取任何变通办法让我的替代品正常工作吗? (将应用程序从有状态的数据模型更改为无状态的数据模型)

Is it normal for the load method in datascroller to be called twice? If so, any workarounds suggested for my alternative to work correctly? (appart from changing from statefull to stateless data model)

使用Primefaces 5.1,JSF2,Glassfish 4.1

Using Primefaces 5.1, JSF2, Glassfish 4.1

推荐答案

不,这是不正常的.这确实是PrimeFaces中的错误.我们在zeef.com上使用它时也发现了它.我们通过创建一个自定义渲染器来绕过它,该渲染器扩展了DataScrollerRenderer,并且仅复制了带有原始实现的encodeMarkup()方法,然后仅注释了以下内容:

No, this is not normal. This is indeed a bug in PrimeFaces. We also discovered it a while ago when using it at zeef.com. We bypassed it by creating a custom renderer extending DataScrollerRenderer and overriding only encodeMarkup() method with the original implementation copypasted and then only the following piece outcommented:

// BUGFIX: outcommented as this is already done in loadChunk() later on.
/*if(ds.isLazy()) {
    loadLazyData(ds, 0, chunkSize);
}*/

您可以通过在webapp的faces-config.xml中进行如下注册来使其运行:

You can get it to run by registering it as below in webapp's faces-config.xml:

<render-kit>    
    <renderer>
        <component-family>org.primefaces.component</component-family>
        <renderer-type>org.primefaces.component.DataScrollerRenderer</renderer-type>
        <renderer-class>com.example.YourDataScrollerRenderer</renderer-class>
    </renderer>
</render-kit>

这篇关于Primefaces惰性Datascroller调用两次加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆