AnsweredAssumed Answered

Pagination: Best practice ??

Question asked by alex54 on Apr 8, 2010
Latest reply on Apr 13, 2010 by alex54
Hi everybody,

For my Web application based on Alfresco 3.1 (Repository services), I need to display the content of a space (the list of file).
Lot of space have a lot of file (500, 1000, maybe more in the futur…).

So, in my own service, I need to manage a pagination in order to get files by bloc (10 by 10 in my case).

But by using for example
, this service return ALL files… So it is not possible to use this service's method…  :oops:

A solution that I found, is to use the searchService in order to call Lucene
, by setting a limit of record to return
params.setLimit(limit); params.setLimitBy(LimitBy.FINAL_SIZE);
. So for the first page, I will fixe the limit to 10 (if I want 10 files per page). for the second page, I will fixe the limit to 20 (and I will filter the result list to take the last 10 files…), and so  one… So If  I want  to see the page #15, I will oblige to set the limit to 150 !! So you can imagine that for first pages my solution is simple, but for all last pages it is the same solution than using

Moreover, and because I need to now the count of files inside the Space (I need to have the count total to calculate the number of page), I use a freemarker  template treatment:

// Create the model object
HashMap model = new HashMap(1, 1.0f);
TemplateNode templateNode = new TemplateNode(spaceNodeRef, this.serviceRegistry, null);
model.put("thespace", templateNode);
// Template freemarker
String xChilds = super.getTemplateService().processTemplateString("freemarker", "<#list thespace.children as child><#if child.isDocument>x</#if></#list>", model);
int totalGeneral = xChilds.length();
Ok I agree that it is not the best solution… but how to know the number of file in a space !???

So, all this explaination, just to show my solution, and to know WHAT IS BEST PRACTICE FOR MANAGE PAGINATION !!
I cannot understand that with all these big project developped over Alfresco, no-one find a GOOD solution.

I read that in the 3.2 version, a pagination system was propose !!!
Maybe in the searchService, because I saw in the 3.2 searchService API this new method:
setSkipCount(int skipCount) with the exaplaintation => Set the skip count - the number of rows to skip at the start of the query.

Is it the case !?

Thansk to everybody,
and sorry for my poor english, I am French  :mrgreen: … and As all froggies I don't speak very well english :D  :D