Play 2 Framework Pagination Stuff Has Changed Version 2.3.7 to 2.4.1

If you are trying to get the computer database example in Play 2 to work which is in 2.3.7 and you are using version 2.4.1 or later, you will find that there are some minor changes to the pagination code.  Here is how to get Play 2 Framework Pagination working.

 

The original code will look something like this:


public static Page page(int page, int pageSize, String sortBy, String order, String filter) {
return
find.where()
.ilike("name", "%" + filter + "%")
.orderBy(sortBy + " " + order)
.fetch("company")
.findPagingList(pageSize)
.setFetchAhead(false)
.getPage(page);
}

Upon you compiling, you will find that FindPagingList is now gone.  Use findPagedList(int,int) instead.  Here is an example that works for  a different table.  Just replace “alias” with “name” and change the fetch to “company” and things should be back working in version 2.4.1


public static PagedList page(int page, int pageSize, String sortBy, String order, String filter) {
return
find.where()
.ilike("alias", "%" + filter + "%")
.orderBy(sortBy + " " + order)
.fetch("version")
.findPagedList(page, pageSize);
}

You will need to import the com.avaje.ebean stuff too.

import com.avaje.ebean.Model;
import com.avaje.ebean.PagedList;

Finally, don’t forget to change your views to use com.avaje.ebean.PagedList too.

Leave a Reply

Your email address will not be published. Required fields are marked *