Spring Data Core

org.springframework.data.web
Class SortHandlerMethodArgumentResolver

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

public class SortHandlerMethodArgumentResolver
extends Object
implements HandlerMethodArgumentResolver

HandlerMethodArgumentResolver to automatically create Sort instances from request parameters or SortDefault annotations.

Since:
1.6
Author:
Oliver Gierke, Thomas Darimont, Nick Williams

Constructor Summary
SortHandlerMethodArgumentResolver()
           
 
Method Summary
protected  List<String> foldIntoExpressions(Sort sort)
          Folds the given Sort instance into a List of sort expressions, accumulating Sort.Order instances of the same direction into a single expression if they are in order.
protected  String getLegacyDirectionParameter(MethodParameter parameter)
           
protected  String getSortParameter(MethodParameter parameter)
          Returns the sort parameter to be looked up from the request.
protected  List<String> legacyFoldExpressions(Sort sort)
          Folds the given Sort instance into two expressions.
 Sort resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
           
 void setFallbackSort(Sort fallbackSort)
          Configures the Sort to be used as fallback in case no SortDefault or SortDefault.SortDefaults (the latter only supported in legacy mode) can be found at the method parameter to be resolved.
 void setPropertyDelimiter(String propertyDelimiter)
          Configures the delimiter used to separate property references and the direction to be sorted by.
 void setQualifierDelimiter(String qualifierDelimiter)
          Configures the delimiter used to separate the qualifier from the sort parameter.
 void setSortParameter(String sortParameter)
          Configure the request parameter to lookup sort information from.
 boolean supportsParameter(MethodParameter parameter)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortHandlerMethodArgumentResolver

public SortHandlerMethodArgumentResolver()
Method Detail

setSortParameter

public void setSortParameter(String sortParameter)
Configure the request parameter to lookup sort information from. Defaults to sort.

Parameters:
sortParameter - must not be null or empty.

setPropertyDelimiter

public void setPropertyDelimiter(String propertyDelimiter)
Configures the delimiter used to separate property references and the direction to be sorted by. Defaults to , which means sort values look like this: firstname,lastname,asc.

Parameters:
propertyDelimiter - must not be null or empty.

setQualifierDelimiter

public void setQualifierDelimiter(String qualifierDelimiter)
Configures the delimiter used to separate the qualifier from the sort parameter. Defaults to _, so a qualified sort property would look like qualifier_sort.

Parameters:
qualifierDelimiter - the qualifier delimiter to be used or null to reset to the default.

supportsParameter

public boolean supportsParameter(MethodParameter parameter)
Specified by:
supportsParameter in interface HandlerMethodArgumentResolver

resolveArgument

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

getSortParameter

protected String getSortParameter(MethodParameter parameter)
Returns the sort parameter to be looked up from the request. Potentially applies qualifiers to it.

Parameters:
parameter - will never be null.
Returns:

getLegacyDirectionParameter

protected String getLegacyDirectionParameter(MethodParameter parameter)

foldIntoExpressions

protected List<String> foldIntoExpressions(Sort sort)
Folds the given Sort instance into a List of sort expressions, accumulating Sort.Order instances of the same direction into a single expression if they are in order.

Parameters:
sort - must not be null.
Returns:

legacyFoldExpressions

protected List<String> legacyFoldExpressions(Sort sort)
Folds the given Sort instance into two expressions. The first being the property list, the second being the direction.

Parameters:
sort - must not be null.
Returns:
Throws:
IllegalArgumentException - if a Sort with multiple Sort.Directions has been handed in.

setFallbackSort

public void setFallbackSort(Sort fallbackSort)
Configures the Sort to be used as fallback in case no SortDefault or SortDefault.SortDefaults (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 Sort data can be found in the request.

Parameters:
fallbackSort - the Sort to be used as general fallback.

Spring Data Core

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