Big paging listbox takes too long to render

asked 2013-02-15 07:50:18 +0800

rjgarcia gravatar image rjgarcia
10 1


I'm having troubles with a listbox. I have a paging listbox that loads the items from database. One of my tables has 850000 records

All the records all load lazy, I only load the first 20 and when the user clicks on the next page or inputs the page number I load this records

To do the pagination I do a select count and assigns the size to the model (I defined a model to do that)

The pagination is fine and there is no problems with tables with less tan 10000 records. The problem is in ListboxDataLoader class. I have in my model 20 items but the ListboxDataLoader creates 850000 items in line 109:

for (; --newcnt >= 0; ++min) {
    if (renderer == null)
        renderer = (ListitemRenderer)getRealRenderer();
    _listbox.insertBefore(newUnloadedItem(renderer, min), next);

I tried to set the render on demand attribute in the listbox but it doesn't works because the event onPaging calls the sync method on ListboxDataLoader and the 850000 items are created

Any ideas how to solve this?

Thanks in advance

delete flag offensive retag edit


Are you using ROD?

sjoshi ( 2013-02-15 10:54:33 +0800 )edit

Look here

hswain ( 2013-02-20 10:44:53 +0800 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2013-02-19 07:01:40 +0800

dennis gravatar image dennis
3669 1 6

updated 2013-02-19 07:16:27 +0800

you should use ROD(ZK EE's feature) or it will new 'skeleton' listitems to listbox (in your case, they are 850000), read the document here

Or, you could build pagination manually for the best performance(control all the detail), here is my example by MVVM + JPA


<window apply="org.zkoss.bind.BindComposer" title="Manual Paging"
    viewModel="@id('vm') @init('org.zkoss.jpa.examples.live.ManualPagingCatViewModel')"
    border="normal" hflex="1" vflex="1" contentStyle="overflow:auto">
        <vbox width="400px">
                totalSize="@bind(vm.totalSize)" pageSize="@bind(vm.pageSize)" activePage="@bind(vm.activePage)"/>
            <listbox model="@bind(vm.availableCategories)"
                selectedItem="@bind(vm.selectedCategory)" rows="@bind(vm.pageSize)">
                <template name="model">
                        <listcell label="@load(each.name)" />
                totalSize="@bind(vm.totalSize)" pageSize="@bind(vm.pageSize)" activePage="@bind(vm.activePage)"/>               
        <vbox visible="@bind(not empty vm.selectedCategory)">
            <label value="@bind(vm.selectedCategory.name)" />
            <listbox model="@bind(vm.selectedCategory.items)">
                <template name="model">
                        <listcell label="@load(each.name)" />


package org.zkoss.jpa.examples.live;

import java.io.Serializable;

import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.jpa.examples.entity.Category;
import org.zkoss.jpa.examples.service.CommonDao;
import org.zkoss.zk.ui.select.annotation.VariableResolver;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import org.zkoss.zkplus.spring.DelegatingVariableResolver;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;

public class ManualPagingCatViewModel implements Serializable{
    private static final long serialVersionUID = 1L;

    CommonDao commonDao;

    Category selectedCategory;
    ListModelList<Category> availableCategories;

    int pageSize = 10;
    int activePage = 0;
    int totalSize;

    public ListModel<Category> getAvailableCategories() {
        return availableCategories;

    public Category getSelectedCategory(){
        return selectedCategory;

    public int getActivePage() {
        return activePage;

    public void setActivePage(int activePage) {
        this.activePage = activePage;

    public int getPageSize() {
        return pageSize;

    public int getTotalSize() {
        return totalSize;

    public void setSelectedCategory(Category selectedCategory) {
            //refresh it to avoid org.hibernate.LazyInitializationException
            this.selectedCategory = commonDao.reload(selectedCategory);
            this.selectedCategory = null;

    public void init(){
        totalSize = commonDao.sizeOf(Category.class);
        availableCategories = new ListModelList(commonDao.list(Category.class,activePage*pageSize,pageSize));

    public void paging(){
        totalSize = commonDao.sizeOf(Category.class);
        if(activePage*pageSize>=totalSize){//the data size was change since last paging, reysnc it.
            activePage = 0;//simply to first page
        availableCategories = new ListModelList(commonDao.list(Category.class,activePage*pageSize,pageSize));
link publish delete flag offensive edit

answered 2014-05-08 14:38:33 +0800

gaucho gravatar image gaucho

Dennis Answer works like a charm!

Thank you very much, you save my day!


link publish delete flag offensive edit

answered 2014-05-08 18:36:08 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16

Here is an online example with about 2.2 Million records. Paged on database.


  1. login
  2. in Menu -> the last entry: Hibernate Statistics

best Stephan

PS: not optimzed for backward

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2013-02-15 07:50:18 +0800

Seen: 147 times

Last updated: May 08 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More