原理是滚动与Lazy加载兼容 [英] Is primefaces live scrolling compatible with Lazy loading
问题描述
here ,我观察到在那里语句
,当分页,排序,过滤或活动滚动时,需要实现一个LazyDataModel来查询数据源发生
现在滚动被提到,但我看不到代码来处理滚动。它只有代码来处理排序,过滤,行计数和分页。有人可以澄清我的困惑,如果两个现场挑逗和懒惰的数据模型实现是相互兼容的,或者我应该添加一些代码来处理实时滚动。
这里有一个小例子:
xhtml
< p: dataTable var =user
value =#{bean.lazyDataModel}
scrollRows =20
liveScroll =true
scrollHeight =500
lazy =true
scrollable =true>
< p:column headerText =name>
< h:outputText value =#{user.name}/>
< / p:column>
< / p:dataTable>
Bean
@ManagedBean
@ViewScoped
public class Bean {
private LazyDataModel< User> lazyDataModel;
@EJB
UserEJB userEJB;
@PostConstruct
public void init(){
lazyDataModel = new LazyUserModel(userEJB);
}
public LazyDataModel< User> getLazyDataModel(){
return lazyDataModel;
}
public void setLazyDataModel(LazyDataModel< User> lazyDataModel){
this.lazyDataModel = lazyDataModel;
}
// userEJB的设置者和获取者
}
LazyUserModel
public class LazyUserModel extends LazyDataModel< User> ; {
private Integer findAllCount;
@EJB
private UserEJB userEJB;
public LazyUserModel(UserEJB userEJB){
this.userEJB = userEJB;
}
@Override
public List< User> load(int first,int pageSize,String sortField,SortOrder sortOrder,
Map< String,String> filters){
列表< User> data = new ArrayList< User>();
// pageSize是在dataable
data = userEJB.findAll(first,pageSize)中的scrollRows =20;
// findAll正在使用query.setFirstResult(first).setMaxResults(pageSize).getResultList()
// rowCount
if(findAllCount == null){
findAllCount = userEJB.findAllCount();
this.setRowCount(findAllCount);
}
返回数据;
}
}
希望这有帮助。 >
I have a datatable where huge data sets need to be displayed.So i decided to go with primefaces live scrolling.I also got to know that to improve datatable performance with huge data sets we need to implement lazy loading.With reference to the primefaces showcase example here,what i observed that there in the statement
, a LazyDataModel needs to be implemented to query the datasource when pagination, sorting, filtering or live scrolling happens
live scrolling is mentioned but i cannot see the code to handle scrolling.It only has the code to handle sorting,filtering,row count and pagination.Can someone please clarify my confusion if both live scolling and lazy datamodel implementation are compatible with each other or should i add some code to handle live scrolling also.
It works exactly the same as if you were having a pagination.
Here's a small example:
xhtml
<p:dataTable var="user"
value="#{bean.lazyDataModel}"
scrollRows="20"
liveScroll="true"
scrollHeight="500"
lazy="true"
scrollable="true">
<p:column headerText="name">
<h:outputText value="#{user.name}" />
</p:column>
</p:dataTable>
Bean
@ManagedBean
@ViewScoped
public class Bean {
private LazyDataModel<User> lazyDataModel;
@EJB
UserEJB userEJB;
@PostConstruct
public void init() {
lazyDataModel = new LazyUserModel(userEJB);
}
public LazyDataModel<User> getLazyDataModel() {
return lazyDataModel;
}
public void setLazyDataModel(LazyDataModel<User> lazyDataModel) {
this.lazyDataModel = lazyDataModel;
}
//setters and getters for userEJB
}
LazyUserModel
public class LazyUserModel extends LazyDataModel<User> {
private Integer findAllCount;
@EJB
private UserEJB userEJB;
public LazyUserModel(UserEJB userEJB) {
this.userEJB = userEJB;
}
@Override
public List<User> load(int first, int pageSize, String sortField, SortOrder sortOrder,
Map<String, String> filters) {
List<User> data = new ArrayList<User>();
// pageSize is scrollRows="20" in the datatable
data = userEJB.findAll(first, pageSize);
// findAll is using query.setFirstResult(first).setMaxResults(pageSize).getResultList()
// rowCount
if (findAllCount == null) {
findAllCount = userEJB.findAllCount();
this.setRowCount(findAllCount);
}
return data;
}
}
Hope this helps.
这篇关于原理是滚动与Lazy加载兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!