Package sk.iway.iwcm.system.datatable
Class PagedListHolder<T>
java.lang.Object
sk.iway.iwcm.system.datatable.PagedListHolder<T>
- Type Parameters:
T- the type of elements in the list
PageListHolder is a utility class for pagination and sorting of Lists.
Replacement for deprecated org.springframework.beans.support.PagedListHolder.
This class is used when you have a List that is not from a database and need to:
- extract a page of data
- sort the data
Usage example:
PageListHolder<MyDTO> holder = new PageListHolder<>(myList);
holder.setSort(new SortDefinition("name", true, true));
holder.resort();
holder.setPage(0);
holder.setPageSize(10);
List<MyDTO> pageContent = holder.getPageList();
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new PageListHolder with an empty source list.PagedListHolder(List<T> source) Create a new PageListHolder with the given source list.PagedListHolder(List<T> source, org.springframework.data.domain.Pageable pageable) Create a new PageListHolder with the given source list and pageable parameters.PagedListHolder(List<T> source, org.springframework.data.domain.Pageable pageable, SortDefinition defaultSort) Create a new PageListHolder with the given source list, pageable parameters and default sort. -
Method Summary
Modifier and TypeMethodDescriptionintgetPage()Get the current page number (0-indexed).intGet the total number of pages.Get the list of elements for the current page.intGet the page size (number of elements per page).getSort()Get the sort definition.Get the source list.voidresort()Resort the list according to the current sort definition.voidsetPage(int page) Set the current page number (0-indexed).voidsetPageSize(int pageSize) Set the page size (number of elements per page).voidsetSort(SortDefinition sort) Set the sort definition.voidSet the source list.
-
Constructor Details
-
PagedListHolder
public PagedListHolder()Create a new PageListHolder with an empty source list. -
PagedListHolder
Create a new PageListHolder with the given source list.- Parameters:
source- the source list
-
PagedListHolder
Create a new PageListHolder with the given source list and pageable parameters. This constructor automatically sets page size, page number and sort from pageable, then performs the sort operation.- Parameters:
source- the source listpageable- the pageable parameters (page, size, sort)
-
PagedListHolder
public PagedListHolder(List<T> source, org.springframework.data.domain.Pageable pageable, SortDefinition defaultSort) Create a new PageListHolder with the given source list, pageable parameters and default sort. This constructor automatically sets page size, page number and sort from pageable, then performs the sort operation. If pageable has no sort, the default sort is used.- Parameters:
source- the source listpageable- the pageable parameters (page, size, sort)defaultSort- the default sort definition to use when pageable has no sort
-
-
Method Details
-
setSource
Set the source list.- Parameters:
source- the source list
-
getSource
Get the source list. Returns a copy of the internal list.- Returns:
- the source list
-
setPage
public void setPage(int page) Set the current page number (0-indexed).- Parameters:
page- the page number (0-indexed)
-
getPage
public int getPage()Get the current page number (0-indexed).- Returns:
- the page number
-
setPageSize
public void setPageSize(int pageSize) Set the page size (number of elements per page).- Parameters:
pageSize- the page size
-
getPageSize
public int getPageSize()Get the page size (number of elements per page).- Returns:
- the page size
-
getPageCount
public int getPageCount()Get the total number of pages.- Returns:
- the page count
-
setSort
Set the sort definition. This does not automatically resort the list. Callresort()after setting the sort definition.- Parameters:
sort- the sort definition
-
getSort
Get the sort definition.- Returns:
- the sort definition
-
resort
public void resort()Resort the list according to the current sort definition. Uses BeanWrapper to access properties for comparison. -
getPageList
Get the list of elements for the current page.- Returns:
- the page list
-