Easy pagination with opencms

Paginación con opencms


Como al parecer el autor de este código borro su sitio o algo y no encontré otro lugar parecido con la infomación lo pondré aquí. Para poder utilizar este código primero deberemos de hacer lo siguiente:


<cms:contentload collector="allInFolderPriorityTitleDesc" pageindex="${pagina}" pagenavlength="3" pagesize="${NumeroPaginas}" param="%(opencms.uri)|elemento">

</cms:contentload>
<cms:contentinfo var="info" scope="request"/>
<cms:contentaccess var="content" scope="page"/>

  •   
  •   mostramos
  •   
</cms:contentload>

Creamos un jsp para incluir el siguiente código
<%--
Created by: Javier Marquez <marquex@gmail.com> <marquex.es>- 02-06-2011

Copyright 2011 Javier Marquez. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:

 1. Redistributions of source code must retain the above copyright notice, this list of
    conditions and the following disclaimer.

 2. Redistributions in binary form must reproduce the above copyright notice, this list
    of conditions and the following disclaimer in the documentation and/or other materials
    provided with the distribution.

THIS SOFTWARE IS PROVIDED BY Javier Marquez 'AS IS' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of Javier Marquez.

*******************
How to use:

Import it from a jsp with a paginated contentload tag. 
You should use the contentinfo tag inside the loop and store its result 
in the "info" request attribute. 
The easiest way to do so is with this code:
<cms:contentinfo var="info" scope="request" /> 

*******************

--%>
<div class="pagination pagination-centered">
<ul>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>

<%
//Store the info in the page Context
pageContext.setAttribute("info", request.getAttribute("info"));

%>
<c:if test="${info.resultSize > info.pageSize}">

<%-- Show the first page if it is not in navigation links --%>
<c:if test="${info.pageNavStartIndex > 1}">
<li><a href="<cms:link><cms:info property="opencms.request.uri" /></cms:link>?page=1">&laquo;</a></li>
</c:if>

<%-- Show the previous page if it is not in navigation links --%>
<c:if test="${info.pageNavStartIndex > 2}">
<li><a href="<cms:link><cms:info property="opencms.request.uri" /></cms:link>?page=${info.pageNavStartIndex - 1}">&lsaquo;</a></li>
</c:if>

<c:forEach var="i" begin="${info.pageNavStartIndex}" end="${info.pageNavEndIndex}">
<c:choose>
<c:when test="${(i == info.pageIndex) || (i == 1 && info.pageIndex == null)}">
<li class="active"><a href="<cms:link><cms:info property="opencms.request.uri" /></cms:link>?page=<c:out value="${i}" />"><c:out value="${i}"/></a></li>
</c:when>
<c:otherwise>
<li><a href="<cms:link><cms:info property="opencms.request.uri" /></cms:link>?page=<c:out value="${i}" />"><c:out value="${i}"/></a></li>
</c:otherwise>
</c:choose>
</c:forEach>

<%-- Show the next page if it is not in navigation links --%>
<c:if test="${info.pageNavEndIndex + 1 < info.pageCount}">
<li><a href="<cms:link><cms:info property="opencms.request.uri" /></cms:link>?page=<c:out value="${info.pageNavEndIndex + 1}" />">&rsaquo;</a></li>
</c:if>

<%-- Show the last page if it is not in navigation links --%>
<c:if test="${info.pageNavEndIndex < info.pageCount}">
<li><a href="<cms:link><cms:info property="opencms.request.uri" /></cms:link>?page=<c:out value="${info.pageCount}" />">&raquo;</a></li>
</c:if>

</c:if>
</ul>
</div>


El original se encontraba aqui easy-pagination-with-opencms
Después con mas tiempo pondré uno para opencms y solr 

Comentarios

Entradas populares