Thursday, June 25, 2009

Java Paging and Sorting

Paging and Sorting in jsp can be done in easy steps using Display Tags java library.

The display tag library is an open source suite of custom tags that
provide high-level web presentation patterns which will work in an MVC
model. The library provides a significant amount of functionality while
still being easy to use.

Here is the simple steps to implements

Customer.java

int id;
String name;
String city;
String phone;

DisplayTagAction.java (Struts Action)


execute(.....){
List list = new ArrayList(); list.add(new Customer(1, "Bill", "Los Angeles", "000000001"));
list.add(new Customer(2, "Kum", "Chennai", "00000000020"));
list.add(new Customer(3, "Tom", "Chicago", "000000003"));
list.add(new Customer(4, "Chian", "Kualalumpur", "0000000004"));
list.add(new Customer(5, "Hong", "Singapore", "000000005"));

list.add(new Customer(6, "Jade", "Holborn", "0000000006"));
request.setAttribute( "test", list );
//...forward to customers.jsp
}

customers.jsp

<display:table cellspacing="4" name="test" export="xls" pagesize="2" requestURI="/displayTag.do" defaultorder="ascending" >
<display:column class="" property="name" sortable="true" title="Name"/>
<display:column property="city" title="City" sortable="true"/>
<display:column property="phone" title="Phone"/>
</display:table>


result will look like:


6 items found,
displaying 1 to 3.
[First/Prev] 1,
2 [Next/Last]






















Name City Phone
Bill Los Angeles 000000001
Kum Chennai 00000000020
Tom Chicago 000000003


Display tags java library can be used for many other purposes like Subtotalling(using column grouping), Exporting data to CSV,Excel,XML,PDF,RTF, etc.,





Resouce :
Download : displaytag library


Tag reference

User guide

No comments:

Post a Comment