Class NarrowPageableHandlerMethodArgumentResolver
java.lang.Object
com.broadleafcommerce.data.tracking.core.web.NarrowPageableHandlerMethodArgumentResolver
- All Implemented Interfaces:
org.springframework.data.web.PageableArgumentResolver
,org.springframework.web.method.support.HandlerMethodArgumentResolver
public class NarrowPageableHandlerMethodArgumentResolver
extends Object
implements org.springframework.data.web.PageableArgumentResolver
More flexible resolver for
Pageable
implementation based on additional 'offset' and
'forward' request params that relate to UnnumberedPageable
and NarrowedPageable
,
respectively. By providing different output based on request params, well known patterns
involving Pageable and PageableDefault params can continue to be leveraged in endpoint classes.
Furthermore, narrowing behavior for a request can be changed on-the-fly (see
ContextInfo.isIgnoreNarrowing()
) and a NarrowedPageable will still work correctly to
resolve a page of records through vanilla Spring repository support. This means that the more
derived Pageable types are still backwards compatible with the less enhanced fetch flows.
The default behavior is to provide the out-of-box Spring Data implementation of Pageable when the 'offset' request parameter is omitted from the request. Next, if 'offset' is included, but 'forward' is omitted, it will provide an implementation of UnnumberedPageable. Finally, should both 'offset' and 'forward' be supplied, it will provide an implementation of NarrowedPageable.
- Author:
- Jeff Fischer
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
protected static final String
protected static final String
protected static final org.springframework.data.domain.Pageable
protected static final String
protected static final String
protected static final String
protected static final org.springframework.data.web.SortHandlerMethodArgumentResolver
protected static final String
-
Constructor Summary
ConstructorDescriptionNarrowPageableHandlerMethodArgumentResolver
(org.springframework.data.web.SortArgumentResolver sortResolver) NarrowPageableHandlerMethodArgumentResolver
(org.springframework.data.web.SortHandlerMethodArgumentResolver sortResolver) -
Method Summary
Modifier and TypeMethodDescriptionprotected org.springframework.data.domain.Pageable
Retrieves the parameter name to be used to determine if this pageable request is incrementally moving forward through the result set, or in reverse.protected int
Retrieves the maximum page size to be accepted.Retrieves the parameter name to be used to determine the number of records to offset.protected PageableProperties
protected String
Retrieves the parameter name to be used to find the page number in the request.protected String
protected String
protected String
Retrieves the parameter name to be used to find the page size in the request.protected org.springframework.data.web.SortArgumentResolver
boolean
isFallbackPageable
(org.springframework.data.domain.Pageable pageable) Returns whether the givenPageable
is the fallback one.protected boolean
Indicates whether to expose and assume 1-based page number indexes in the request parameters.org.springframework.data.domain.Pageable
resolveArgument
(org.springframework.core.MethodParameter methodParameter, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest, org.springframework.web.bind.support.WebDataBinderFactory binderFactory) void
setFallbackPageable
(org.springframework.data.domain.Pageable fallbackPageable) Configures thePageable
to be used as fallback in case noPageableDefault
orPageableDefault
(the latter only supported in legacy mode) can be found at the method parameter to be resolved.void
setForwardParameterName
(String forwardParameterName) Sets the parameter name to be used to determine if this pageable request is incrementally moving forward through the result set, or in reverse.void
setOffsetParameterName
(String offsetParameterName) Sets the parameter name to be used to determine the number of records to offset.void
setOneIndexedParameters
(boolean oneIndexedParameters) Configures whether to expose and assume 1-based page number indexes in the request parameters.void
setPageableProperties
(PageableProperties properties) void
setPageParameterName
(String pageParameterName) Configures the parameter name to be used to find the page number in the request.void
Configures a general prefix to be prepended to the page number and page size parameters.void
setQualifierDelimiter
(String qualifierDelimiter) The delimiter to be used between the qualifier and the actual page number and size properties.void
setSizeParameterName
(String sizeParameterName) Configures the parameter name to be used to find the page size in the request.boolean
supportsParameter
(org.springframework.core.MethodParameter parameter)
-
Field Details
-
DEFAULT_SORT_RESOLVER
protected static final org.springframework.data.web.SortHandlerMethodArgumentResolver DEFAULT_SORT_RESOLVER -
INVALID_DEFAULT_PAGE_SIZE
- See Also:
-
DEFAULT_FORWARD_PARAMETER
- See Also:
-
DEFAULT_OFFSET_PARAMETER
- See Also:
-
DEFAULT_QUALIFIER_DELIMITER
- See Also:
-
DEFAULT_PAGE_PARAMETER
- See Also:
-
DEFAULT_SIZE_PARAMETER
- See Also:
-
DEFAULT_PREFIX
- See Also:
-
DEFAULT_PAGE_REQUEST
protected static final org.springframework.data.domain.Pageable DEFAULT_PAGE_REQUEST
-
-
Constructor Details
-
NarrowPageableHandlerMethodArgumentResolver
public NarrowPageableHandlerMethodArgumentResolver() -
NarrowPageableHandlerMethodArgumentResolver
public NarrowPageableHandlerMethodArgumentResolver(org.springframework.data.web.SortHandlerMethodArgumentResolver sortResolver) -
NarrowPageableHandlerMethodArgumentResolver
public NarrowPageableHandlerMethodArgumentResolver(org.springframework.data.web.SortArgumentResolver sortResolver)
-
-
Method Details
-
setPageableProperties
-
supportsParameter
public boolean supportsParameter(org.springframework.core.MethodParameter parameter) - Specified by:
supportsParameter
in interfaceorg.springframework.web.method.support.HandlerMethodArgumentResolver
-
resolveArgument
public org.springframework.data.domain.Pageable resolveArgument(org.springframework.core.MethodParameter methodParameter, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest, org.springframework.web.bind.support.WebDataBinderFactory binderFactory) - Specified by:
resolveArgument
in interfaceorg.springframework.web.method.support.HandlerMethodArgumentResolver
- Specified by:
resolveArgument
in interfaceorg.springframework.data.web.PageableArgumentResolver
-
setFallbackPageable
public void setFallbackPageable(org.springframework.data.domain.Pageable fallbackPageable) Configures thePageable
to be used as fallback in case noPageableDefault
orPageableDefault
(the latter only supported in legacy mode) can be found at the method parameter to be resolved.If you set this to Optional#empty(), be aware that you controller methods will get null handed into them in case no
Pageable
data can be found in the request. Note, that doing so will require you supply bot the page and the size parameter with the requests as there will be no default for any of the parameters available.- Parameters:
fallbackPageable
- thePageable
to be used as general fallback.
-
isFallbackPageable
public boolean isFallbackPageable(org.springframework.data.domain.Pageable pageable) Returns whether the givenPageable
is the fallback one.- Parameters:
pageable
- can be null.- Returns:
- Since:
- 1.9
-
getMaxPageSize
protected int getMaxPageSize()Retrieves the maximum page size to be accepted. This allows to put an upper boundary of the page size to prevent potential attacks trying to issue anOutOfMemoryError
.- Returns:
- the maximum page size allowed.
-
setPageParameterName
Configures the parameter name to be used to find the page number in the request. Defaults topage
.- Parameters:
pageParameterName
- the parameter name to be used, must not be null or empty.
-
getPageParameterName
Retrieves the parameter name to be used to find the page number in the request. Defaults topage
.- Returns:
- the parameter name to be used, never null or empty.
-
setSizeParameterName
Configures the parameter name to be used to find the page size in the request. Defaults tosize
.- Parameters:
sizeParameterName
- the parameter name to be used, must not be null or empty.
-
getSizeParameterName
Retrieves the parameter name to be used to find the page size in the request. Defaults tosize
.- Returns:
- the parameter name to be used, never null or empty.
-
setPrefix
Configures a general prefix to be prepended to the page number and page size parameters. Useful to namespace the property names used in case they are clashing with ones used by your application. By default, no prefix is used.- Parameters:
prefix
- the prefix to be used or null to reset to the default.
-
setQualifierDelimiter
The delimiter to be used between the qualifier and the actual page number and size properties. Defaults to_
. So a qualifier offoo
will result in a page number parameter offoo_page
.- Parameters:
qualifierDelimiter
- the delimiter to be used or null to reset to the default.
-
setOneIndexedParameters
public void setOneIndexedParameters(boolean oneIndexedParameters) Configures whether to expose and assume 1-based page number indexes in the request parameters. Defaults to false, meaning a page number of 0 in the request equals the first page. If this is set to true, a page number of 1 in the request will be considered the first page.- Parameters:
oneIndexedParameters
- the oneIndexedParameters to set
-
isOneIndexedParameters
protected boolean isOneIndexedParameters()Indicates whether to expose and assume 1-based page number indexes in the request parameters. Defaults to false, meaning a page number of 0 in the request equals the first page. If this is set to true, a page number of 1 in the request will be considered the first page.- Returns:
- whether to assume 1-based page number indexes in the request parameters.
-
getForwardParameterName
Retrieves the parameter name to be used to determine if this pageable request is incrementally moving forward through the result set, or in reverse. Defaults toforward
. This parameter is only used when the request is targetingNarrowedPageable
.- Returns:
- the parameter name to be used
-
setForwardParameterName
Sets the parameter name to be used to determine if this pageable request is incrementally moving forward through the result set, or in reverse. Defaults toforward
. This parameter is only used when the request is targetingNarrowedPageable
.- Parameters:
forwardParameterName
- the parameter name to be used
-
getOffsetParameterName
Retrieves the parameter name to be used to determine the number of records to offset. Defaults tooffset
. This parameter is only used when the request is targetingUnnumberedPageable
andNarrowedPageable
.- Returns:
- the parameter name to be used
-
setOffsetParameterName
Sets the parameter name to be used to determine the number of records to offset. Defaults tooffset
. This parameter is only used when the request is targetingUnnumberedPageable
andNarrowedPageable
.- Parameters:
offsetParameterName
- the parameter name to be used
-
getFallbackPageable
protected org.springframework.data.domain.Pageable getFallbackPageable() -
getSortResolver
protected org.springframework.data.web.SortArgumentResolver getSortResolver() -
getPageableProperties
-
getQualifierDelimiter
-
getPrefix
-