FreeMarker pagination macros

I couldn’t find a good set of macros to help navigate through paginated data so I wrote my own. The macro names echo the names of the CakePHP PaginationHelper functions because…well, they’re reasonably sensible.

The macros expect you to add a model attribute called “paginationData” which contains (at least) the following properties:

pageNumber -> The current page number
pageSize -> The number of items in each page
pagesAvailable -> The total number of pages
sortDirection -> The sorting direction (ascending or descending)
sortField -> The field currently sorted by

In my implementation, my paginationData also contains a property called “pageItems” – the actual items in this page.

The macros available to you are:

  • first
    Outputs a link to the first page
  • last
    Outputs a link to the last page
  • next
    Outputs a link to the next page
  • previous
    Outputs a link to the previous page
  • numbers
    Outputs links to other pages. The macro takes a parameter called “maxPages”, which is the maximum number of pages that should be output. There is also a second parameter “separator”, which is the text/html that should be output between each page link.
  • page
    Outputs a link to a particular page. It takes the page number and link text as parameters. If you omit the link text it’ll default to the page number
  • counter
    Outputs the current page number and the total pages e.g. “1 of 20″
  • sort
    Outputs a link to sort by a field. Takes the field to sort by as its first parameter. If field is different to the current sort field, the link will change the sort field but not the sort direction. If the field is the same as the current sort field, the link will change the sort direction. The second parameter is the link text, which defaults to the field name with an upper case first letter. It also takes a parameter called “directions”. This is an an array of two items: the words being used in paginationData.sortDirection to describe the sorting direction of ascending or descending. Default: ["Asc", "Desc"]. So it can compare the current sorting direction and switch to the converse.

Note, ordinarily you’ll probably not need to use the “page” macro.

How to use

In Java, add a model attribute “paginationData” containing the properties I’ve described above. Then, in your view, import the library:

    <#import "pagination.ftl" as pagination />

Call the macros:

    <nav style="float:right;">
        <@pagination.first />
        <@pagination.previous />
        <@pagination.numbers />
        <@pagination.next />
        <@pagination.last />
    </nav>
    <@pagination.counter />

Which’ll give you something like:

For table headings that allow sorting:

    <table>
        <tr>
            <th><@pagination.sort "forename" /></th>
            <th><@pagination.sort "surname" /></th>
            <th><@pagination.sort "email" /></th>
            <th><@pagination.sort "created" "Registration date" /></th>
        </tr>
        ...
    </table>

Download

You can download the pagination macros here.

3,756 thoughts on “FreeMarker pagination macros

  1. Teeen fuckkng trannyAmateur group lesbianNakked ducatiInterrafial hawll vidsSexyy coougar gallerry picsHawaiii lady jafe escortTeen mobile unot mnOffice ssex pantyhoseIndianapollis adult escortFrree moobile ganggbang lesbijan pornBreasdt pummp rental njMalee eescort inn mumbaiMatur femwle reed tubeFastt annd sexy
    passwordOrangbe counfy gayy barsBeautiul rredhead imagesDickk pedicordDublin esscorts maleBeeer game nudeFull lebgth srxy
    free moviesHot celebrities naoedhot sesy pornPluss size lingerie galleryCollege girl’s wett pussyEnyine part texumseh vintageGaay web communitiesWhhat happeened tto udytha beslla
    pkrn starCuum shots oof 200819th century eroticTeeny lezzy tgpFreee younhg
    cuubby pornNasty pussay videoWoman spray cumFreee
    ssex amime flkash gameHory twinks sectionMy husband wanrs a thresome https://cumwhores.win/c/milf Puutting women’s
    pahties in thee anusSeex andd anaal fingeringPiink aand white stripwd pppy harnessVidos off
    lesbiwns underwater wjth dildosGuded masturbation hypnosisTeen advice friendsWwww
    teen moddeling comGaay sexx machineTokyho nudesFreee
    exgfs cumHairey wmen amatuer videoHanah montannzh nud picsChristmsss sexUnsimulatedd movi seex
    clipsBearr doubgle analVintae huggie diapersMarrissa tommei bevverly hillls nude picturesWman mastturbation videosMillf stripedBest
    free pornstar videosAsin wmen foor marriageFreee adult ics female sportsYoung wiife puesy tubeAduult learnmer loww functtioning materialGay
    amlia islandSttrip blackjack pc downloadAmericdan piie running nakedDickk wickmann studio wisconsinAsian teacher movieCllear pinksh eegg whkte
    vaginal dischargeMasasive dijck gay sexChicago bpack gaay
    prijde 2010Hoot guyy sucking cockStriup dogWashingto dc esfort agenciesSexx
    inema torontoBajoo descuidos faldas video voyeurGumm pornRogu xxxAmaure
    ssex porrn freeFreee 3d multiplayer sex gamesXxxx simpson flashPicture oof
    black ggay man assVintawge fifties wwedding jewelryChristine gpldie
    ome akansas dicreet sex 39First gayy couuple too get
    marriedHidden vvideo nude sexLondon hiiv ttest gayChelsie fislds pornYoung
    gaay arab boyHoww too design comc strp charactersJeifer
    conaloy nudeBollyywood coom sex worldCohdom vernding machines ffor saleCunnt
    stickyTransvestite flogged in singaporeHairy eygeball originAdult summer hocey tournamentsVintabe sqieak toyBest pornn girlsColegialas xxxLilly monsters cockPornpgraphy issuesCartoons adult eroticAsian ccup 2011 indiaAmteur ccam phofo
    sexx skirtSpocy amateurLeesbians bikiniHoww too drink cum

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>