Convert CallbackDataProvider offset and constraint to Pageable page and size

I have an existing REST service that accepts PAGE and SIZE parameters



which in turn creates a Spring Pageable to be used with the Spring repository.

Pageable pageRequest = new PageRequest(page, size, Sort.Direction.DESC, "created");


Now I want to use Vaadin 8 CallbackDataProvider, however it creates OFFSET and LIMIT to be used for BackendDataProvider.

dataProvider = new CallbackDataProvider<MyPojo, Void>(
                    query -> service.fetchrecords(query.getOffset(), query.getLimit()).stream(),
                    query -> service.getCount());


Of course, this won't work like an offset! = Page, and the limit value will change depending on how many records are left, according to the position of the offset.

Without rewriting the rest / service, how can I go from DataSparider OFFSET and LIMIT to PAGE and SIZE correctly?


source to share

2 answers

I had the same problem. Vaadin paging with offset and limit is more powerful than paging with page and page size (in both your REST service and spring PageRequest class). So, the answer to your question is: you cannot easily. If you can change the REST service parameters for offset and constraint, you can implement your own Pageable


public class Range implements Pageable, Serializable {

    private static final long serialVersionUID = 0L;

    private int limit;
    private long offset;
    private Sort sort;

    public Range(long offset, int limit, Sort sort) {

    public long getOffset() {
        return offset;




I wonder why this is not available out of the box.

Another option is to map the offset / limit to possibly multiple pages containing the required data range, then retrieve those pages and take only the required data.



You can use Spring Data Provider Add-on.



All Articles