1

Big paging listbox takes too long to render

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

rjgarcia gravatar image rjgarcia
10 1

Hi

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

Comments

Are you using ROD?

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

Look here

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

3 Answers

Sort by ยป oldest newest most voted
2

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

dennis gravatar image dennis
3669 1 6
http://www.javaworld.com....

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

zul

<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">
    <hbox>
        <vbox width="400px">
            <paging 
                onPaging="@command('paging')"
                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">
                    <listitem>
                        <listcell label="@load(each.name)" />
                    </listitem>
                </template>
            </listbox>
            <paging 
                onPaging="@command('paging')"
                totalSize="@bind(vm.totalSize)" pageSize="@bind(vm.pageSize)" activePage="@bind(vm.activePage)"/>               
        </vbox>     
        <vbox visible="@bind(not empty vm.selectedCategory)">
            <label value="@bind(vm.selectedCategory.name)" />
            <listbox model="@bind(vm.selectedCategory.items)">
                <template name="model">
                    <listitem>
                        <listcell label="@load(each.name)" />
                    </listitem>
                </template>
            </listbox>
        </vbox>
    </hbox>
</window>

java

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;

@VariableResolver(DelegatingVariableResolver.class)
public class ManualPagingCatViewModel implements Serializable{
    private static final long serialVersionUID = 1L;

    @WireVariable
    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) {
        if(selectedCategory!=null){
            //refresh it to avoid org.hibernate.LazyInitializationException
            this.selectedCategory = commonDao.reload(selectedCategory);
        }else{
            this.selectedCategory = null;
        }
    }

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

    @Command 
    @NotifyChange({"totalSize","availableCategories"}) 
    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
0

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

gaucho gravatar image gaucho
6

Dennis Answer works like a charm!

Thank you very much, you save my day!

Luis

link publish delete flag offensive edit
0

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

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

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

http://zk-web.de/zksample2/

  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

Follow
2 followers

RSS

Stats

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