Saturday, November 7, 2009

Simple steps to use diaplaytag for pagination

Display tag is a high level opensource suite which is used for paginating a page. You can paginate a content and display it. The followings are the steps which you have to follow

1. download the latest version of display tag binary folder from http://sourceforge.net/projects/displaytag/files/

2. extract it and copy the displaytag-1.2.jar, displaytag-export-poi-1.2.jar and displaytag-portlet-1.2.jar(optional if you are not using this for portlet) to your lib
folder

3. first put the list which you get from the controller to a session or request scope as follows(in jsp)

<% ArrayList myList= (ArrayList) request.getAttribute("myList"); if(myList != null){ session.setAttribute("myList1" , myList); } %>

here i put the result to an ArrayList and set it in session scope.

3. go to your view page(where you are going to show the web content) and put your list inside the display tag as follows.
<display:table name="sessionScope.myList1" pagesize="5" uid="row" id="one-column-emphasis" >
<display:column title=" Name " property="name"/>
<display:column title="Age" property="age" />
<display:column title="Address" property="address" />
</display:table>


"pagesize" - number of items per page
"uid" - unique id,you can use id for this but then you cannot use id for another thing
"id" - this is a css tag.you can give your own one

you can give variable for title. then you have to use this code

<display:column title="<%=Address%>" property="address" />

That's all .you did the pagination. you can see the paginated page when you run the application