Package com.wavemaker.runtime.resolver
Class WMPageableHandlerMethodArgumentResolver
java.lang.Object
com.wavemaker.runtime.resolver.WMPageableHandlerMethodArgumentResolver
- All Implemented Interfaces:
org.springframework.web.method.support.HandlerMethodArgumentResolver
- Direct Known Subclasses:
ServiceBasedPageableHandlerMethodArgumentResolver
public class WMPageableHandlerMethodArgumentResolver
extends Object
implements org.springframework.web.method.support.HandlerMethodArgumentResolver
Created by sunilp on 24/9/15.
In spring-data-commons 1.9.X, oneIndexedParameters is applying for both page size and number.Where as in
spring-data-commons older version like 1.8.*. oneIndexedParameters parameter was applied for only page number.
This class extends functionality of PageableHandlerMethodArgumentResolver and handling page size similar to older version.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an instance of this resolved with a defaultSortHandlerMethodArgumentResolver.WMPageableHandlerMethodArgumentResolver(org.springframework.data.web.SortHandlerMethodArgumentResolver sortResolver) Constructs an instance of this resolver with the specifiedSortHandlerMethodArgumentResolver. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertPageableUniqueness(org.springframework.core.MethodParameter parameter) static voidassertQualifiersFor(Class<?>[] parameterTypes, Annotation[][] annotations) static org.springframework.beans.factory.annotation.QualifierfindAnnotation(Annotation[] annotations) protected intRetrieves the maximum page size to be accepted.protected StringRetrieves the parameter name to be used to find the page number in the request.protected StringgetParameterNameToUse(String source, org.springframework.core.MethodParameter parameter) Returns the name of the request parameter to find thePageableinformation in.protected StringRetrieves the parameter name to be used to find the page size in the request.static <T> TgetSpecificPropertyOrDefaultFromValue(Annotation annotation, String property) booleanisFallbackPageable(org.springframework.data.domain.Pageable pageable) Returns whether the givenPageableis the fallback one.protected booleanIndicates whether to expose and assume 1-based page number indexes in the request parameters.org.springframework.data.domain.PageableresolveArgument(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) voidsetFallbackPageable(org.springframework.data.domain.Pageable fallbackPageable) Configures thePageableto be used as fallback in case noPageableDefaultor(the latter only supported in legacy mode) can be found at the method parameter to be resolved.invalid reference
PageableDefaultsvoidsetMaxPageSize(int maxPageSize) Configures the maximum page size to be accepted.voidsetOneIndexedParameters(boolean oneIndexedParameters) Configures whether to expose and assume 1-based page number indexes in the request parameters.voidsetPageParameterName(String pageParameterName) Configures the parameter name to be used to find the page number in the request.voidConfigures a general prefix to be prepended to the page number and page size parameters.voidsetQualifierDelimiter(String qualifierDelimiter) The delimiter to be used between the qualifier and the actual page number and size properties.voidsetSizeParameterName(String sizeParameterName) Configures the parameter name to be used to find the page size in the request.booleansupportsParameter(org.springframework.core.MethodParameter parameter)
-
Constructor Details
-
WMPageableHandlerMethodArgumentResolver
public WMPageableHandlerMethodArgumentResolver()Constructs an instance of this resolved with a defaultSortHandlerMethodArgumentResolver. -
WMPageableHandlerMethodArgumentResolver
public WMPageableHandlerMethodArgumentResolver(org.springframework.data.web.SortHandlerMethodArgumentResolver sortResolver) Constructs an instance of this resolver with the specifiedSortHandlerMethodArgumentResolver.- Parameters:
sortResolver- The sort resolver to use
-
-
Method Details
-
setFallbackPageable
public void setFallbackPageable(org.springframework.data.domain.Pageable fallbackPageable) Configures thePageableto be used as fallback in case noPageableDefaultor(the latter only supported in legacy mode) can be found at the method parameter to be resolved. If you set this to null, be aware that you controller methods will get null handed into them in case noinvalid reference
PageableDefaultsPageabledata 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- thePageableto be used as general fallback.
-
isFallbackPageable
public boolean isFallbackPageable(org.springframework.data.domain.Pageable pageable) Returns whether the givenPageableis the fallback one.- Since:
- 1.9
-
setMaxPageSize
public void setMaxPageSize(int maxPageSize) Configures 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. Defaults toDEFAULT_MAX_PAGE_SIZE.- Parameters:
maxPageSize- the maxPageSize to set
-
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. Defaults toDEFAULT_MAX_PAGE_SIZE.- 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 offoowill result in a page number parameter offoo_page.- Parameters:
qualifierDelimiter- the delimter 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.
-
supportsParameter
public boolean supportsParameter(org.springframework.core.MethodParameter parameter) - Specified by:
supportsParameterin 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) throws Exception - Specified by:
resolveArgumentin interfaceorg.springframework.web.method.support.HandlerMethodArgumentResolver- Throws:
Exception
-
getParameterNameToUse
protected String getParameterNameToUse(String source, org.springframework.core.MethodParameter parameter) Returns the name of the request parameter to find thePageableinformation in. Inspects the givenMethodParameterforQualifierpresent and prefixes the given source parameter name with it.- Parameters:
source- the basic parameter name.parameter- theMethodParameterpotentially qualified.- Returns:
- the name of the request parameter.
-
getSpecificPropertyOrDefaultFromValue
-
assertPageableUniqueness
public static void assertPageableUniqueness(org.springframework.core.MethodParameter parameter) -
assertQualifiersFor
-
findAnnotation
public static org.springframework.beans.factory.annotation.Qualifier findAnnotation(Annotation[] annotations)
-