Package zone.berna.datatablesajax
Class TableResponseGenerator
- java.lang.Object
-
- zone.berna.datatablesajax.TableResponseGenerator
-
public class TableResponseGenerator extends java.lang.Object
Singleton class that generates aTableResponse
given aTableRequest
, functions to retrieve counters and elements, and an array of the fields used as columns.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <E> TableResponse
generateResponse(TableRequest tableRequest, java.util.function.LongSupplier totalCountSupplier, TotalFilteredFunction totalFilteredFunction, PaginatedSearchFunction<E> paginatedSearchFunction, java.lang.String... fields)
Generates aTableResponse
given aTableRequest
, functions to retrieve counters and elements, and an array of the fields used as columns.static TableResponseGenerator
instance()
Retrieves the instance of this class.
-
-
-
Method Detail
-
instance
public static TableResponseGenerator instance()
Retrieves the instance of this class.- Returns:
- the instance
-
generateResponse
public <E> TableResponse generateResponse(TableRequest tableRequest, java.util.function.LongSupplier totalCountSupplier, TotalFilteredFunction totalFilteredFunction, PaginatedSearchFunction<E> paginatedSearchFunction, java.lang.String... fields)
Generates aTableResponse
given aTableRequest
, functions to retrieve counters and elements, and an array of the fields used as columns.- Type Parameters:
E
- the element used in the table. Must implement bean-style getters for the fields- Parameters:
tableRequest
- theTableRequest
received from the viewtotalCountSupplier
- a Supplier that retrieves the total count of entries in the tabletotalFilteredFunction
- a Function that returns the count of entries matching the given query string.The query string is always non-null, trimmed and in lowercase.
An empty query string should result in the same value returned by
totalCountSupplier
paginatedSearchFunction
- a Function that returns the requested interval of (filtered) elements, sorted by the given field, in ascending/descending order. The query string is always trimmed and in lowercase. An empty query string should return the interval of all elementsfields
- an array of field names of the element used in the table, in the same order of the columns- Returns:
- the TableResponse instance, which should be returned to the view as a JSON response object
-
-