You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Flori <fl...@gmail.com> on 2011/04/05 16:56:38 UTC

load list view when scroll

I have a problem with an aplication that displays a list of documents using
ListView:
The current design is the following:
- a ListView is created with nr of items = nrOfdocuments/50; the ListView is
added to a scroller
- for each item of this ListView a new panel Batch is created (which
represents a batch of documents - max 50 documents); 
- this Batch class creates another ListView with maximum 50 items (each item
representing a panel with a document's details - items are loaded only when
the scroll reaches them)
For ex: 
- for a total number of 1000 documents: - 20 objects of type Batch will be
created => 20 ListView objects will be created
The problem is that trying to load large amounts of documents (> 10000) will
end with java out of memory exception. 
I want to improve this design, by keeping only one Batch loaded in memory
once (so only max 50 documents) and to clear all the other ListView objects
previously created which are not used anymore.
Do you have any ideas that can help me?

Thank you!

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/load-list-view-when-scroll-tp3428291p3428291.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: load list view when scroll

Posted by Flori <fl...@gmail.com>.
Hello Michael,

Thank you for your fast response.

I still didn't manage to solve the problem. 
I attached the code to see exactly the design and to explain better:

I have this ListView attached to a scroll (getBatchNumbers() is a model that
will return number of batches = total number of docs/50) 

new ListView("batchElem", getBatchNumbers()) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void populateItem(final ListItem item) {
                final int batchNum = item.getIndex();
                final Model loaded = new Model(Boolean.valueOf(batchNum <
PRELOAD_BATCHES_COUNT));
                item.setOutputMarkupId(true);
                item.add(new AttributeAppender("class", new Model() {
                    @Override
                    public String getObject() {
                        if (loaded.getObject().booleanValue()) {
                            return "loaded";
                        }
                        return "";
                    }
                }, " "));

                final Component comp;
                if (_showGrid) {
                	comp = new GridBatch("content", loaded, batchNum);                	
                } else {
                	comp = new Batch("content", loaded, batchNum);            		                	
                }
                item.add(comp);

                item.add(new AjaxLink("showLink", new Model("show")) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onClick(final AjaxRequestTarget target) {                    	
                    	loaded.setObject(Boolean.TRUE);                    	
                        target.addComponent(comp);
                    }

                    /**
                     * {@inheritDoc}
                     */
                    @Override
                    public boolean isVisible() {
                        return !loaded.getObject();
                    }
                });
            }
        };

And the Batch class:
private Batch(final String id, final IModel show, final int batchNum) {
            super(id);
            setOutputMarkupId(true);
            add(createHeightAppender());
            add(createEmptyClassAppender());
            _batchNum = batchNum;
            _show = show;
            addComponents();
        }   
	protected void addComponents() {
	     add(createItemsList(););			
	}

public ListView createItemsList() {
           return new ListView("item", createItemsForCurrentBatch()) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void populateItem(final ListItem item) {
                    item.add(createPanelForItem("batchItemContent",
_batchNum, item.getIndex(), item.getModel()));                    
                }

                @Override
                public boolean isVisible() {                     
                  return _show.getObject();
                }
            };           
        }
createItemsForCurrentBatch() will return a model which will load 50
documents once.

Considering this design, I will keep in memory all the loaded ListViews.
I tried to clear the list views previously loaded, but then I lose the model
attached to them and upon scrolling to them again, there is nothing
reloaded.
I can not use pagination, I have to keep the scroll.
Do you have any idea how can I clear (and if it's possible) the list views
previously loaded? But in such a manner that if I scroll to them again, to
reload the documents corresponding to the respective Batch?

Thank you very much!



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/load-list-view-when-scroll-tp3428291p3430677.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: load list view when scroll

Posted by Michael O'Cleirigh <mi...@rivulet.ca>.
Hi Flori,

Have you considered using a DataTable with its automatic pagination?  I 
think using an ISortableDataProvider<Batch> would be easier than an 
IModel<List<Batch>> in terms of controlling the segmentation of the data.

You need to let the loadable detachability of wicket work by reducing 
the amount of data per page and also injecting page refeshes (either 
standard or ajax) to load the next set of data.

I think you need to look at your problem and understand that the page 
size is wickets way of constraining the data into processably chunks but 
your ever growing listview is essentially the same problem.  You need to 
find a way to segment that search into processable parts so as to not 
keep all the data in memory at the same time.

Another thing to look at is if you are detaching your models at the end 
of the request.

Using the datatable-autocomplete wicketstuff project we have an index of 
100,000 elements in memory and use a datatable to serve subsets to users 
without running out of memory (ok we do set -Xmx1024).

Regards,

Mike
> ListView:
> The current design is the following:
> - a ListView is created with nr of items = nrOfdocuments/50; the ListView is
> added to a scroller
> - for each item of this ListView a new panel Batch is created (which
> represents a batch of documents - max 50 documents);
> - this Batch class creates another ListView with maximum 50 items (each item
> representing a panel with a document's details - items are loaded only when
> the scroll reaches them)
> For ex:
> - for a total number of 1000 documents: - 20 objects of type Batch will be
> created =>  20 ListView objects will be created
> The problem is that trying to load large amounts of documents (>  10000) will
> end with java out of memory exception.
> I want to improve this design, by keeping only one Batch loaded in memory
> once (so only max 50 documents) and to clear all the other ListView objects
> previously created which are not used anymore.
> Do you have any ideas that can help me?
>
> Thank you!
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/load-list-view-when-scroll-tp3428291p3428291.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org