Basically, you have to create it yourself, as far as I know. Therefore, if you want to have the same pagination template as in the example example, you will have to recreate css.
To create a custom one is quite simple: The first paginator datatable is set to false because you are going to create a regular one. Then make two links on top of your data table:
this is from new.xhtml:
<div class="nextPrevBlock"> <h:panelGroup rendered="#{page>0}" style="margin-right:1em;"> <h:link outcome="new.xhtml"> <f:param name="page" value="#{page - 1}"/> <div class="btnLink"> <h:outputText value="#{strings.previous}"></h:outputText> </div> </h:link> </h:panelGroup> <h:panelGroup> <h:link outcome="new.xhtml"> <f:param name="page" value="#{page + 1}"/> <div class="btnLink"> <h:outputText value="#{strings.next}"/> </div> </h:link> </h:panelGroup> </div>
Save the page to a Managed Bean using getters and setters. Then just execute the query with the page:
//it requestScoped @EJB private ElemService elementService; private List<Element> elementList; @PostConstruct public void init() { FacesContext fc = FacesContext.getCurrentInstance(); Map<String, String> paramsMap = fc.getExternalContext() .getRequestParameterMap(); try { page = Integer.parseInt(paramsMap.get("page")); if (page < 0) page = 0; } catch (Exception e) { page = 0; } getElementsOfPage(page); } public void getElementsOfPage(int page) { elementList = elementService.getElemByPage(page); }
Then in your service:
@Override public List<Element> giveElementList(int page) { Query query = em.createQuery(SELECT_NEWEST_THREADS); query.setFirstResult(page * NUMBER_OF_ELEMENTS_PER_PAGE); query.setMaxResults(NUMBER_OF_ELEMENTS_PER_PAGE); return query.getResultList(); }
setFirstResult() is the first result, so you need to put the value of the page once per element after page. And setMaxResults is just an element for the page you want.
You will need to customize it to suit your needs. I hope this help.
Ced source share