Hi Daniel,

unfortunately I have neither some simple project nor article explaining this. I have implemented it in my own meta framework which is part of a big commercial application. (It consists currently of 6 or 7 different Eclipse projects, so it would be really difficult to extract 'clearly' the code, you are asking for.) I'm attaching just three classes from my early 'playground' code. Sorry, it's the best I can offer right now :( You will not be able to compile this (because the rest of my stuff have nothing to do with fetching itself and would be more complicated as helpful) but you can track the approach. There are three methods, which shows how it works and how to get ride of duplicated (exactly: multiple) fetching of the same data: getPage() and doFetchPage() in DataPagedListDataModel<T> and getDataModel() in PagedListFoto (which extends the DataPagedListDataModel indirectly)

The solution is to separate the fetching call into own method in base abstract class. (Why it should be abstract is explained in Wiki.)

   private int _lastStartRow = -1;
   private int _lastPageSize = -1;
   private DataPage<T> _lastPage = null;
private DataPage<T> doFetchPage(int startRow, int pageSize){ if ((_lastPage == null) || (_lastStartRow != startRow) || (_lastPageSize != pageSize)){
           _log.debug("**Fetch: required -> fetching...");
           _lastPage = fetchPage(startRow, pageSize);
           //store values to chech next time
           _lastStartRow = startRow;
           _lastPageSize = pageSize;
       }else{
           _log.debug("***Fetch: not required (already fetched)!");
       }
       return _lastPage;
   }

I store then the startRow and pageSize values and check it every time the new fetch is 'requested'. Just take a look at my debug statements entire the code, they should be self explained. The fetching take place exactly one time for particularly page of data.

One more thing to be clearly explained here: the getDataModel() of 'enclosing' nested class (PagedListFoto in my case) MUST BE CALLED TWICE, since you have two components in your JSP -> the DataTable and the Scroller and both are accessing this property. So you have to handle this situation yourself, i.e. directly in getter:

public DataModel getDataModel() {
     _log.debug("-------------- getDataModel() called -------");
       if (dataModel == null) {
           dataModel = new LocalDataModel(rowsPerPage);
       }
       return dataModel;
}

I hope it helps.

Regards,
paul

P.S. As mentioned, I'm not using t:dataScroller since it's buggy in combination with AJAX (at least: it WAS buggu in 1.1.4 and 1.1.5), but I think, it makes no difference regarding fetching approach itself. I've send my code with few minor improvements to Adrian Mitev (author of original component, which was published at https://ajax4jsf.dev.java.net/servlets/ProjectDocumentList?folderID=6510&expandFolder=6510&folderID=5320). If you are interested in this component, just ask him about it.

daniel ccss schrieb:

Thanks!!!

Paul do you have a simple project where I can see how all working together, I'm really tire of search and search for solutions and nothing , I´m new in this and really need help, thanks!!


P.D: have you publish some article explaining how all this works (your DataScroller using AjaxDataScroller and the approach of the wiki)?... you should i know that many people will appreciate it!


Attachment: pagination-playground.rar
Description: Binary data

Reply via email to