Class ListPager<T>
- java.lang.Object
-
- org.jivesoftware.util.ListPager<T>
-
- Type Parameters:
T
- The type of item being displayed
public class ListPager<T> extends Object
This class provides an easy way to page through a filterable list of items from a JSP page.
It is up to the caller of the class to specify the filter, if required, in the form of a
predicate
. To ensure that search parameters are maintained when paging through the list, it's also necessary to supply a list of input field identifiers that should be included as part of the request when accessing another page. These field identifiers are used to extract the value of the field, and copy it to a hidden form that is used for the actual submission. This means each search criteria has two form fields associated with it - the visible field that the users types in, and in the hidden form that is submitted.The reason for this is that the location of the input fields on the screen may not always be appropriate for a form - for example, if the fields are location within a table, the form must wrap the whole table, which would preclude the use of any other forms within cells in that table.
These input fields will also be modified so that pressing Enter/Return when the fields has focus will automatically submit the form.
-
-
Constructor Summary
Constructors Constructor Description ListPager(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, List<T> items, String... additionalFormFields)
Creates a unfiltered list pager.ListPager(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, List<T> items, Predicate<T> filter, String... additionalFormFields)
Creates a unfiltered list pager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getCurrentPageNumber()
int
getFilteredItemCount()
int
getFirstItemNumberOnPage()
String
getHiddenFields()
List<T>
getItemsOnCurrentPage()
String
getJumpToPageForm()
int
getLastItemNumberOnPage()
String
getPageFunctions()
String
getPageLinks()
int
getPageSize()
String
getPageSizeSelection()
static String
getQueryString(javax.servlet.http.HttpServletRequest request, char prefix, String... additionalFormFields)
int
getTotalItemCount()
int
getTotalPages()
boolean
isFiltered()
-
-
-
Constructor Detail
-
ListPager
public ListPager(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, List<T> items, String... additionalFormFields)
Creates a unfiltered list pager.- Parameters:
request
- the request object for the page in questionresponse
- the response object for the page in questionitems
- the list of items to display on the pageadditionalFormFields
- 0 or more input field identifiers (NOT form field names) to include in requests for other pages
-
ListPager
public ListPager(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, List<T> items, Predicate<T> filter, String... additionalFormFields)
Creates a unfiltered list pager.- Parameters:
request
- the request object for the page in questionresponse
- the response object for the page in questionitems
- the complete list of items to display on the pagefilter
- the filter to apply to the complete listadditionalFormFields
- 0 or more input field identifiers (NOT form field names) to include in requests for other pages
-
-
Method Detail
-
getTotalItemCount
public int getTotalItemCount()
- Returns:
- the total number unfiltered items
-
getFilteredItemCount
public int getFilteredItemCount()
- Returns:
- the number of items after the filter has been applied
-
getItemsOnCurrentPage
public List<T> getItemsOnCurrentPage()
- Returns:
- the filtered items on the current page
-
getCurrentPageNumber
public int getCurrentPageNumber()
- Returns:
- the current page
-
getPageSize
public int getPageSize()
- Returns:
- the maximum number of items on the page
-
getFirstItemNumberOnPage
public int getFirstItemNumberOnPage()
- Returns:
- the first item number on the page
-
getLastItemNumberOnPage
public int getLastItemNumberOnPage()
- Returns:
- the last item number on the page
-
getTotalPages
public int getTotalPages()
- Returns:
- the total number of pages
-
isFiltered
public boolean isFiltered()
- Returns:
true
if the the supplied filter has restricted the number of items to display, otherwisefalse
-
getPageSizeSelection
public String getPageSizeSelection()
- Returns:
- a string that contains HTML for selecting the page size
-
getPageLinks
public String getPageLinks()
- Returns:
- a string that contains links to other pages in the list
-
getHiddenFields
public String getHiddenFields()
- Returns:
- the list of hidden fields required to maintain the current list pager state
-
getQueryString
public static String getQueryString(javax.servlet.http.HttpServletRequest request, char prefix, String... additionalFormFields)
- Parameters:
request
- The request to retrieve the values fromprefix
- The first char of the query string - either `?` or `&`additionalFormFields
- 0 or more form field names to include in requests for other pages- Returns:
- a query string required to maintain the current list pager state
-
getJumpToPageForm
public String getJumpToPageForm()
- Returns:
- a string with an HTML form containing hidden fields, used for navigating between pages
-
getPageFunctions
public String getPageFunctions()
- Returns:
- a string containing JavaScript that helps with navigation between pages
-
-