new play! module — paginate

One of the things I miss from JSF programming is the ability to use easily pluggable controls.  Play! isn’t really a component oriented framework, so it doesn’t provide that ability out of the box.  But because it’s so extensible it’s easy enough to fill in this gap.

I just uploaded a new module for the Play! framework to github.  It’s called Play—Paginate and does exactly what it sounds like it does: it gives you the ability to easily create paginating tables with minimal impact on your code.

Simply render the paginator from your controller.  You can instruct it to load the values from the database, or wrap a List you already loaded.

    public static void index() {
        Paginator entities = new ModelPaginator(TestModel.class,
"field=?", "whatever").setPageSize(4);
        render(entities);
    }

Simply render the paginator in your view by adding this stylesheet:

<link rel="stylesheet" type="text/css" media="screen" 
href="@{'/public/stylesheets/play-pagination.css'}">

And use the tags #{paginate.list}, which is a drop-in replacement for #{list}, and #{paginate.controls}, to display the pagination controls:

#{paginate.list items:entities, as:'ref'/}
#{paginate.controls items:entities /}

Then you’ll get something like this:

Play--Paginate control

Easy peasy.

Notes

  1. lmcalpin posted this