I am developing a simple application using Spring + Thymeleaf. On one of the pages I have a list of items which needs to be paginated.
Ideally I would like to only s
Another option would be Ben Thurley's solution. We have implemented it and it's working smoothly: http://bthurley.wordpress.com/2012/07/18/spring-mvc-with-restful-datatables/
It lacks couples of items, like the filter argument for the search, but you can easily add via the PagingCriteria object and make sure to add it on the TableParamArgumentResolver.
public class TableParamArgumentResolver implements WebArgumentResolver {
private static final String S_ECHO = "sEcho";
private static final String I_DISPLAY_START = "iDisplayStart";
private static final String I_DISPLAY_LENGTH = "iDisplayLength";
private static final String I_SORTING_COLS = "iSortingCols";
private static final String I_SORT_COLS = "iSortCol_";
private static final String S_SORT_DIR = "sSortDir_";
private static final String S_DATA_PROP = "mDataProp_";
private static final String I_DATA_SEARCH = "sSearch";
public Object resolveArgument(MethodParameter param, NativeWebRequest request)
throws Exception {
TableParam tableParamAnnotation = param.getParameterAnnotation(TableParam.class);
if (tableParamAnnotation != null) {
HttpServletRequest httpRequest = (HttpServletRequest) request.getNativeRequest();
String sEcho = httpRequest.getParameter(S_ECHO);
String sDisplayStart = httpRequest.getParameter(I_DISPLAY_START);
String sDisplayLength = httpRequest.getParameter(I_DISPLAY_LENGTH);
String sSortingCols = httpRequest.getParameter(I_SORTING_COLS);
String sSearch = httpRequest.getParameter(I_DATA_SEARCH);
Integer iEcho = Integer.parseInt(sEcho);
Integer iDisplayStart = Integer.parseInt(sDisplayStart);
Integer iDisplayLength = Integer.parseInt(sDisplayLength);
Integer iSortingCols = Integer.parseInt(sSortingCols);
List sortFields = new ArrayList();
for (int colCount = 0; colCount < iSortingCols; colCount++) {
String sSortCol = httpRequest.getParameter(I_SORT_COLS + colCount);
String sSortDir = httpRequest.getParameter(S_SORT_DIR + colCount);
String sColName = httpRequest.getParameter(S_DATA_PROP + sSortCol);
sortFields.add(new SortField(sColName, sSortDir));
}
PagingCriteria pc = new PagingCriteria(iDisplayStart, iDisplayLength, iEcho, sortFields, sSearch);
return pc;
}
return WebArgumentResolver.UNRESOLVED;
}
}