2
respostas

Paginação JSF

Boa tarde eu gostaria de saber como faço paginação com jsf puro sem depender de prime faces e essas tecnologias externas ?

2 respostas

Fala Marcus, tudo bem?

Vai dar um certo trabalho fazer sem nenhum framework, você vai ter que controlar a paginação na mão:

Bean:

// Set currentPage, totalPages and pages.
        currentPage = (totalRows / rowsPerPage) - ((totalRows - firstRow) / rowsPerPage) + 1;
        totalPages = (totalRows / rowsPerPage) + ((totalRows % rowsPerPage != 0) ? 1 : 0);
        int pagesLength = Math.min(pageRange, totalPages);
        pages = new Integer[pagesLength];

        // firstPage must be greater than 0 and lesser than totalPages-pageLength.
        int firstPage = Math.min(Math.max(0, currentPage - (pageRange / 2)), totalPages - pagesLength);

        // Create pages (page numbers for page links).
        for (int i = 0; i < pagesLength; i++) {
            pages[i] = ++firstPage;
        }

View:

        <!--The paging buttons-->
            <h:commandButton value="first" action="#{jsfPaginationBean.pageFirst}"
                             disabled="#{jsfPaginationBean.firstRow == 0}" />
            <h:commandButton value="prev" action="#{jsfPaginationBean.pagePrevious}"
                             disabled="#{jsfPaginationBean.firstRow == 0}" />
            <h:commandButton value="next" action="#{jsfPaginationBean.pageNext}"
                             disabled="#{jsfPaginationBean.firstRow + jsfPaginationBean.rowsPerPage >= jsfPaginationBean.totalRows}" />
            <h:commandButton value="last" action="#{jsfPaginationBean.pageLast}"
                             disabled="#{jsfPaginationBean.firstRow + myBean.rowsPerPage >= jsfPaginationBean.totalRows}" />
            <h:outputText value="Page #{jsfPaginationBean.currentPage} / #{jsfPaginationBean.totalPages}" />

Bom dia Otávio Felipe do Prado, eu realmente não entendi como seria essa implementação.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software