Spring Data Core

org.springframework.data.web
Class PageableHandlerMethodArgumentResolver

java.lang.Object
  extended by org.springframework.data.web.PageableHandlerMethodArgumentResolver
All Implemented Interfaces:
HandlerMethodArgumentResolver
Direct Known Subclasses:
HateoasPageableHandlerMethodArgumentResolver

public class PageableHandlerMethodArgumentResolver
extends Object
implements HandlerMethodArgumentResolver

Extracts paging information from web requests and thus allows injecting Pageable instances into controller methods. Request properties to be parsed can be configured. Default configuration uses request parameters beginning with DEFAULT_PAGE_PARAMETERDEFAULT_QUALIFIER_DELIMITER.

Since:
1.6
Author:
Oliver Gierke, Nick Williams

Field Summary
static PageableHandlerMethodArgumentResolver LEGACY
          Deprecated. 
 
Constructor Summary
PageableHandlerMethodArgumentResolver()
          Constructs an instance of this resolved with a default SortHandlerMethodArgumentResolver.
PageableHandlerMethodArgumentResolver(SortHandlerMethodArgumentResolver sortResolver)
          Constructs an instance of this resolver with the specified SortHandlerMethodArgumentResolver.
 
Method Summary
protected  int getMaxPageSize()
          Retrieves the maximum page size to be accepted.
protected  String getPageParameterName()
          Retrieves the parameter name to be used to find the page number in the request.
protected  String getParameterNameToUse(String source, MethodParameter parameter)
          Returns the name of the request parameter to find the Pageable information in.
protected  String getSizeParameterName()
          Retrieves the parameter name to be used to find the page size in the request.
protected  boolean isOneIndexedParameters()
          Indicates whether to expose and assume 1-based page number indexes in the request parameters.
 Pageable resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
           
 void setFallbackPageable(Pageable fallbackPageable)
          Configures the Pageable to be used as fallback in case no PageableDefault or PageableDefaults (the latter only supported in legacy mode) can be found at the method parameter to be resolved.
 void setMaxPageSize(int maxPageSize)
          Configures the maximum page size to be accepted.
 void setOneIndexedParameters(boolean oneIndexedParameters)
          Configures whether to expose and assume 1-based page number indexes in the request parameters.
 void setPageParameterName(String pageParameterName)
          Configures the parameter name to be used to find the page number in the request.
 void setPrefix(String prefix)
          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(MethodParameter parameter)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEGACY

@Deprecated
public static final PageableHandlerMethodArgumentResolver LEGACY
Deprecated. 
A PageableHandlerMethodArgumentResolver preconfigured to the setup of PageableArgumentResolver. Use that if you need to stick to the former request parameters an 1-indexed behavior. This will be removed in the next major version (1.7). So consider migrating to the new way of exposing request parameters.

Constructor Detail

PageableHandlerMethodArgumentResolver

public PageableHandlerMethodArgumentResolver()
Constructs an instance of this resolved with a default SortHandlerMethodArgumentResolver.


PageableHandlerMethodArgumentResolver

public PageableHandlerMethodArgumentResolver(SortHandlerMethodArgumentResolver sortResolver)
Constructs an instance of this resolver with the specified SortHandlerMethodArgumentResolver.

Parameters:
sortResolver - The sort resolver to use
Method Detail

setFallbackPageable

public void setFallbackPageable(Pageable fallbackPageable)
Configures the Pageable to be used as fallback in case no PageableDefault or PageableDefaults (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 no Pageable data can be found in the request.

Parameters:
fallbackPageable - the Pageable to be used as general fallback.

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 an OutOfMemoryError. Defaults to DEFAULT_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 an OutOfMemoryError. Defaults to DEFAULT_MAX_PAGE_SIZE.

Returns:
the maximum page size allowed.

setPageParameterName

public void setPageParameterName(String pageParameterName)
Configures the parameter name to be used to find the page number in the request. Defaults to page.

Parameters:
pageParameterName - the parameter name to be used, must not be null or empty.

getPageParameterName

protected String getPageParameterName()
Retrieves the parameter name to be used to find the page number in the request. Defaults to page.

Returns:
the parameter name to be used, never null or empty.

setSizeParameterName

public void setSizeParameterName(String sizeParameterName)
Configures the parameter name to be used to find the page size in the request. Defaults to size.

Parameters:
sizeParameterName - the parameter name to be used, must not be null or empty.

getSizeParameterName

protected String getSizeParameterName()
Retrieves the parameter name to be used to find the page size in the request. Defaults to size.

Returns:
the parameter name to be used, never null or empty.

setPrefix

public void setPrefix(String prefix)
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

public void setQualifierDelimiter(String qualifierDelimiter)
The delimiter to be used between the qualifier and the actual page number and size properties. Defaults to _. So a qualifier of foo will result in a page number parameter of foo_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(MethodParameter parameter)
Specified by:
supportsParameter in interface HandlerMethodArgumentResolver

resolveArgument

public Pageable resolveArgument(MethodParameter methodParameter,
                                ModelAndViewContainer mavContainer,
                                NativeWebRequest webRequest,
                                WebDataBinderFactory binderFactory)
                         throws Exception
Specified by:
resolveArgument in interface HandlerMethodArgumentResolver
Throws:
Exception

getParameterNameToUse

protected String getParameterNameToUse(String source,
                                       MethodParameter parameter)
Returns the name of the request parameter to find the Pageable information in. Inspects the given MethodParameter for Qualifier present and prefixes the given source parameter name with it.

Parameters:
source - the basic parameter name.
parameter - the MethodParameter potentially qualified.
Returns:
the name of the request parameter.

Spring Data Core

Copyright © 2011-2013-2013 Pivotal. All Rights Reserved.