Introduction

The pager is a custom tag simple and extensible used to render a paginated and sorted list. It is part of the SU4JD (SpedUp4JavaDeveloper) that have the only scope of speed up the development of the project. Pager is born when I wrote the code generator for maven to create the simple page to show the list of data. The difference by the other similar tools is the simplicity, you can have a paginated list without define the columns, its reconfigurability and extendibility.

Simple

The tag library can be used in a simple way suppling only the list and the type of the item.

        <p:pager items="${items}" itemType="test.my.MyClass" />

The Pager use the itemType attribute to navigate all attributes of the type and show in the list. Pager show complex attribute too.

For example:

        public class MyClass2 {
                private String attr1;
                // ...
                // getters and setters
        }
public class MyClass {
        private String mcAttr1;
        private MyClass2 class2;
        // ...
        // getters and setters
}

The list show a table with colums:

  • property mcAttr1 with description "Mc attr1"
  • propeety class2.attr1 with description "Class2 Attr1"

    Note: without columns definition itemType is mandatory

Configurable

Pager tag is highly configurable. There are many methods to configure the system.

  • Pager is supplied with a default configuration in it/dangelo/claudio/pager/default-pager-config.properties.
  • You can overwrite or add configiguration with a custom properties file. You must set it in the ConfigInitializer listener.
  • You can overwrite or add configiguration in a jsp using the setProperty tag

Custom or automatic paging and sorting

Pager tag manage two type of paging and/or sorting. With custom management the developer must manage the paging and/or sorting (with the controller or servlet). With automatic management the tag manage the paging and/or sorting.

You can supply these informations with attributes '''externalPaging''' and/or '''externalSorting''' that receive a boolean value.

Custom show of data

You can indicate which property show in the list using the column tag.

<p:pager items="${items}" size="15">
<p:column property="mcAttr1">My Attribute 1</p:column>
<p:column property="class2.attr1"></p:column>
</pager>

If you don't set the title property or a text in the column body the system creates a title using a render.

Custom renders

Pager is highly customizable. You can modify how the system must show data using many implementation.

  • TitleRender : used to convert a property name in the column title
  • CellRender : used to render a value of the cell
  • TemplateEngine : used to render the table with all datas.

    You can set the renders in the jsp or can be setted how defaults using a custom properties file configuration

Linkable data

There are two method to link table data:

  • Row link : the link is fired when click on the row
  • Cell link : the link is fired when click on the cell

    You can use both methods in the same table.

    Links can be setted using the link tag, this tag can be use with an internal expression language like the unified expression language with the difference of ':' instead of '$' or '#'

    <p:pager items="${items}" size="15">
            <p:setProperty key="sortProperty">sprop2</p:setProperty>
            <p:setProperty key="sortDir">sdir2</p:setProperty>
            <p:setProperty key="offset">offset2</p:setProperty>
            <p:setProperty key="max">max2</p:setProperty>
            <p:column property="gattoPreferito.nome">
            <p:link url=":{pageContext.servletContext.contextPath}/detail?nome=:{pager.item.nome}&index=:{pager.index}</p:link>
            </p:column>
            <p:column property="nome">Nome persona</p:column>
    </p:pager>

    or

    <p:pager items="${items}" size="15">
            <p:setProperty key="sortProperty">sprop2</p:setProperty>
            <p:setProperty key="sortDir">sdir2</p:setProperty>
            <p:setProperty key="offset">offset2</p:setProperty>
            <p:setProperty key="max">max2</p:setProperty>
            <p:column property="gattoPreferito.nome">
            <p:link url=":{pageContext.servletContext.contextPath}/detail?nome=:{pager.item.nome}">
                    <p:parameter name="index">:{pager.index}</p:parameter>
            </p:link>
            </p:column>
            <p:column property="nome">Nome persona</p:column>
    </p:pager>

    How you can see the parameter can be setted in the url attribute of link tag or with parameter tag