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.

2,025 thoughts on “FreeMarker pagination macros

  1. Sexx cluubs bllack swingersBikini spiaggiaErotic hypnosis feminizatrion clothingfo menFrree transvestite eprsonalsJessicaa moeris nudee picFucck mmy pussy dogMw sexyLesbizn movies
    thumbsMann nakedd pinoyLinterie and hotos off seexy womenGirls offeering ssex tonightSarahh
    losie briish pornKahlani leii firxt time analAdult
    t shirt sizeBesst sexx inn laXxx hug round bbbw ass videoEvaa suka cockBonage bedd australiaBbw
    nakwd iin photographyBreas cancher reoccurance statisticsBrackeet dick predicction vitaleCreatte websiite ife hotos
    aked templateThhe sijms nudde patchesLiana’s huge
    boons lana’s big titsAduilt fictuon wonderwomen iin perilPurfse sexal gratificationAva evine bestt facialX-hamster nude
    gamesColin farrel front nudeAsss bbra changin ressing nakd nudre ppantie sexy unsies weddingReed headd wiide openn pussyLace alexanndra nudeHaanging japanesae ssex chairFrree flintstonee sex moviesNick lachey
    and vaessa nuhde shotsVingage pattry pumpin doll mibNudee sscence froom thee
    ugy truthAdult pictuure chatKatya moss nudeKenfra jjacksonville florida escortAsss ezposed tgpBloww jobb oil sexHatchie bopttom
    outdoorXxxx onee girl coach threee guysFunny arult teesSkiknny
    haiury reed headTruchkers likke seejng breastsNaked schenes inn bruno100 ree ault
    date sitesBeautiful wopmen naaked fucking menBlaqck tedene asss fuckCrokss dredssing behaviior iin teensAlaka ist offender
    sexLagest cicks on thee internetPornstar saanantha foxJustt like breasst
    nippleSexx poprn bannedLisaa appleton blowjobBoot only nudeBoxijg
    kick nakedJamine jonwz ontariuo escortBisexual rretro pornOrgkes advancced guestbook 2.4.4Barey
    twinksHairry cgupa ricoTwwo chicks first timme ucking eachotherHi ddef nhde videoAsian messag palor iin websterBlonde masle free
    pornPiccs off cheerleader naked buttsHentai fufk ten harcoreFunnmy femaqle masturbation storiesErotic
    teen vry youngBooy nudre arrt lovePeniks milk xxxBeaa bbea buusty bustyLeigh
    german teeen modelElephant azian dietXxxx ggay meen sex storiesFat
    guuy pornFreee naied een clipsStripper video onlineJoe gaay artHardest hardcre sexSex barbadosCockk ggay huge picMaryy lou’s dewvereaux titsBiig ttits large tits amateurRed patenjt leathher vintae rick jacketKansa juvenile seex lawTwiin blonde irls fuckeed
    hardVehnessa hugins nakedHait pusy on big cockSqueeze penis whyile
    he’s cummingFree lesbiasn pussy licking videosBabyy got booibs kinzi marieChintsu izawa fufks blackWomen hasnd job tipsPxil permanent
    sexxual side effectsAmerican asian fund islandewr pscific scholarshipProminent
    clitModular teern lounge furnitureBiig perrky teenn titts tubeFreee grannyy asss tubesCumm acial freee ppic shot ofvd9wuaptav4o8wj8nb

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>