vraptor-paginator

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

GroupId

GroupId

br.com.caelum.vraptor
ArtifactId

ArtifactId

vraptor-paginator
Last Version

Last Version

4.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

vraptor-paginator
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project URL

Project URL

http://maven.apache.org
Source Code Management

Source Code Management

http://github.com/caelum/vraptor-paginator

Download vraptor-paginator

How to add to project

<!-- https://jarcasting.com/artifacts/br.com.caelum.vraptor/vraptor-paginator/ -->
<dependency>
    <groupId>br.com.caelum.vraptor</groupId>
    <artifactId>vraptor-paginator</artifactId>
    <version>4.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/br.com.caelum.vraptor/vraptor-paginator/
implementation 'br.com.caelum.vraptor:vraptor-paginator:4.0.0'
// https://jarcasting.com/artifacts/br.com.caelum.vraptor/vraptor-paginator/
implementation ("br.com.caelum.vraptor:vraptor-paginator:4.0.0")
'br.com.caelum.vraptor:vraptor-paginator:jar:4.0.0'
<dependency org="br.com.caelum.vraptor" name="vraptor-paginator" rev="4.0.0">
  <artifact name="vraptor-paginator" type="jar" />
</dependency>
@Grapes(
@Grab(group='br.com.caelum.vraptor', module='vraptor-paginator', version='4.0.0')
)
libraryDependencies += "br.com.caelum.vraptor" % "vraptor-paginator" % "4.0.0"
[br.com.caelum.vraptor/vraptor-paginator "4.0.0"]

Dependencies

compile (9)

Group / Artifact Type Version
br.com.caelum : vraptor jar 4.0.0.Final
org.hibernate : hibernate-core jar 4.3.0.Final
org.hibernate.javax.persistence : hibernate-jpa-2.0-api jar 1.0.1.Final
org.hibernate : hibernate-entitymanager jar 4.3.0.Final
hsqldb : hsqldb jar 1.8.0.10
org.jboss.weld.servlet : weld-servlet jar 2.1.1.Final
org.jboss.weld.se : weld-se-core jar 2.1.1.Final
log4j : log4j jar 1.2.17
org.slf4j : slf4j-log4j12 jar 1.7.5

provided (4)

Group / Artifact Type Version
org.mortbay.jetty : servlet-api jar 3.0.20100224
org.glassfish.web : javax.el jar 2.2.4
javax.servlet : jstl jar 1.2
javax.servlet.jsp : jsp-api jar 2.2

test (4)

Group / Artifact Type Version
junit : junit jar 4.8.2
org.mockito : mockito-core jar 1.8.5
org.hamcrest : hamcrest-core jar 1.3
org.hamcrest : hamcrest-library jar 1.3

Project Modules

There are no modules declared in this project.

VRaptor-paginator

Installing

Add to your pom:

  <dependency>
  	<groupId>br.com.caelum.vraptor</groupId>
  	<artifactId>vraptor-paginator</artifactId>
  	<version>4.0.0-SNAPSHOT</version>
  </dependency>
  

Example with JPA

  @Inject
  private JPAPaginatedQuery query;

  @Get("/{page.number}")
  public void home(Page page) {
    //this code could be in your DAO
  	Paginator<Music> paginator = query
  			.jpql("select m from Music m left join m.musicOwners mo where mo.owner=:user")
  			.setParameter("user", user).paginate(page);

  	result.include("paginator", paginator);
  }
  

Example with Hibernate

    @Inject
    private HibernatePager query;
    @Inject
    private Session session;

    @Get("/{page.number}")
    public void home(Page page) {
      //this code could be in your DAO
    	Paginator<Music> paginator = query
    			.paginate(session.createQuery("select m from Music m left join m.musicOwners mo where mo.owner=:user")
    			.setParameter("user", user),page);

    	result.include("paginator", paginator);
    }

Usage of Paginator in your view

  <paginator:roller pages="${paginator.pages}"/>

This tag just encapsulate a simple foreach. Take a look.

    <c:forEach var="page" items="${pages}">
    	<li class="${page.classes}">
    		<c:if test="${!page.hasLink() }">${page.content }</c:if>
    		<c:if test="${page.hasLink() }">
    			<a href="./${page.content}">${page.content }</a>
    		</c:if>
    	</li>
    </c:forEach>
    

It is not complicated, if you need to implement your version of a pagination. The getClasses method is responsible to return a css class that can be applied to the <li> element. VRaptor-paginator has a three different types of a PageDefinition. Let's see the CurrentPage implementation:

    public class CurrentPage implements PageDefinition {

    	private final String content;

    	public CurrentPage(Integer next) {
    		this.content = "" + next;
    	}

    	@Override
    	public String getContent() {
    		return content;
    	}

    	@Override
    	public String getClasses() {
    		return "pagination-page pagination-current";
    	}

    	@Override
    	public boolean hasLink() {
    		return false;
    	}

You can take a look in the other two classes, LinkedPageDefinition and ThreeDotsDefinition.

br.com.caelum.vraptor

Caelum

Versions

Version
4.0.0