Unverified Commit 4e9f7a6c authored by Gautier de Saint Martin Lacaze's avatar Gautier de Saint Martin Lacaze
Browse files

Fix #658 : Pager not working properly

Since the removal of "X-Total-Pages" and "X-Total" headers, all paginations use the kaminari counter.
In this mode, kaminari counter is reset to -1 during the call of the last page. This part is correct.
Then when we call the `current()` method of the pager to get the current page. This method call the same `page` method than the `next` method. In this method the pager check if there is element before checking if we call for the current page. It throws NoSuchElementException erroneously.

To fix, I change the check sequence. First I check ifthe user call the current page. If so, we return the corresponding items. If not we check if there is such elements and call the API.
parent db8f9254
......@@ -306,12 +306,6 @@ public class Pager<T> implements Iterator<List<T>>, Constants {
*/
public List<T> page(int pageNumber) {
if (pageNumber > totalPages && pageNumber > kaminariNextPage) {
throw new NoSuchElementException();
} else if (pageNumber < 1) {
throw new NoSuchElementException();
}
if (currentPage == 0 && pageNumber == 1) {
currentPage = 1;
return (currentItems);
......@@ -321,6 +315,12 @@ public class Pager<T> implements Iterator<List<T>>, Constants {
return (currentItems);
}
if (pageNumber > totalPages && pageNumber > kaminariNextPage) {
throw new NoSuchElementException();
} else if (pageNumber < 1) {
throw new NoSuchElementException();
}
try {
setPageParam(pageNumber);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment