Index: magnolia-module-standard-templating-kit/src/main/java/info/magnolia/module/templatingkit/util/STKPager.java =================================================================== --- magnolia-module-standard-templating-kit/src/main/java/info/magnolia/module/templatingkit/util/STKPager.java (revision 37501) +++ magnolia-module-standard-templating-kit/src/main/java/info/magnolia/module/templatingkit/util/STKPager.java (working copy) @@ -95,7 +95,14 @@ } protected int getOffset() { - return ((getCurrentPage() -1) * maxResultsPerPage); + int offset = ((getCurrentPage() -1) * maxResultsPerPage); + // when requested page is out of range of the actual number of items, + // set offset to offset of the last page + if(offset > count) { + int pages = count / maxResultsPerPage; + offset = pages * maxResultsPerPage; + } + return offset; } public int getCurrentPage() { @@ -174,7 +181,10 @@ maxResultsPerPage = Integer.MAX_VALUE; try { if( content.hasNodeData("maxResultsPerPage") ){ - maxResultsPerPage = (int) content.getNodeData("maxResultsPerPage").getLong(); + int max = (int) content.getNodeData("maxResultsPerPage").getLong(); + if(max > 0) { + maxResultsPerPage = max; + } } position = "top";