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 {
Listusers = ... // 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"));
Listusers = ... // 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!
Did you ever try to have pagination for a custom macro built in confluence ? Are you aware of any macro which does pagination ?
ReplyDeleteI didn't do this myself by maybe following way could help.
ReplyDeleteif you need pagination in usual page, you inherit action from *AbstractEntityPaginationAction* which contains
*protected bucket.core.actions.PaginationSupport paginationSupport*.
In your plugin you could directly create *paginationSupport* and fill it with actual data.
.vm page for macro could contain pagination bar as in ordinary page
* #pagination($action.paginationSupport "page.action?") *
last thing to do - pass selected page number to main page and then back to macro as an additional parameter.
Sorry I don't have such concrete experience so maybe wrong in some points.
Good luck!