Confluence provides items pagination out of the box but I couldn't find any reference in developer documentation. Standard page navigation bar looks like this:

Here are the easy steps to implement it for your own list of items:
- extend your action class from AbstractEntityPaginationAction
- insert pagination macro in viewusers.vm page
- implement page.action
- view current items in page
public class ViewUsersAbstractEntityPaginationAction provides
extends AbstractEntityPaginationAction {
}
protected bucket.core.actions.PaginationSupport paginationSupport;
which you can use in your action:
public String execute() throws Exception {
List users = ... // load users here
paginationSupport.setItems(users);
paginationSupport.setPageSize(preferredPageSize);
return SUCCESS;
} #pagination($action.paginationSupport "page.action?")where page.action is the action name which will be called when you select a page. Pagination macro then adds a parameter startIndex, that's why you need a question mark (?) at the end
public String page() throws Exception {
HttpServletRequest req =
ServletActionContext.getRequest();
int startIndex =
Integer.parseInt(req.getParameter("startIndex"));
List users = ... // load users
paginationSupport.setItems(users);
paginationSupport.setPageSize(preferredPageSize);
paginationSupport.setStartIndex(startIndex);
return SUCCESS;
} #foreach( $user inPaginationSupport allows to control page size (number of items per page) so you may provide a selector in web page for page size and save it in user session.
$action.paginationSupport.page.iterator())
...
#end
That's it!