Class PagedListHolder<T>

java.lang.Object
sk.iway.iwcm.system.datatable.PagedListHolder<T>
Type Parameters:
T - the type of elements in the list

public class PagedListHolder<T> extends Object
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 Details

    • PagedListHolder

      public PagedListHolder()
      Create a new PageListHolder with an empty source list.
    • PagedListHolder

      public PagedListHolder(List<T> source)
      Create a new PageListHolder with the given source list.
      Parameters:
      source - the source list
    • PagedListHolder

      public PagedListHolder(List<T> source, org.springframework.data.domain.Pageable pageable)
      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 list
      pageable - 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 list
      pageable - the pageable parameters (page, size, sort)
      defaultSort - the default sort definition to use when pageable has no sort
  • Method Details

    • setSource

      public void setSource(List<T> source)
      Set the source list.
      Parameters:
      source - the source list
    • getSource

      public List<T> 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

      public void setSort(SortDefinition sort)
      Set the sort definition. This does not automatically resort the list. Call resort() after setting the sort definition.
      Parameters:
      sort - the sort definition
    • getSort

      public SortDefinition 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

      public List<T> getPageList()
      Get the list of elements for the current page.
      Returns:
      the page list