Recently, due to project requirements, I want to upgrade the original displaytag1.0 to displaytag1.1. In fact, the reason for the upgrade is very simple. 1.0 is really silly, and all the data needs to be loaded at one time on each page, low Efficiency :)
The biggest improvement of Version 1.1 can be said to have finally supported the long-awaited multipart loading function, allowing users to load as much data as they want. version 1.1 supports two paging methods. The first method is to implement its Org. displaytag. pagination. paginatedlist interface. The second method is to modify the page and background at the same time to implement the paging function. there are many introductions on how to use the second paging method on the Internet, and the official documents are also detailed, so here I will mainly introduce how I use the first method for paging, and this method is also officially recommended for paging (I am exploring it myself, haha, it's not good to be surprised)
First, write an implementation class for this interface.
/**
* Paginatedlistimpl
* User: shrek_xu
* Date: 2006-5-30
* Time: 20:35:18
*
* Totalnum: Number of all entries
* Current page number of currentpage
* Objectsperpage displays the number of entries per page
* List the data to be displayed on this page
*/
Public class paginatedlisthelper implements paginatedlist {
Private list;
Private int pagenumber = 1;
Private int objectsperpage = 20;
Private int fulllistsize = 0;
Private string sortcriterion;
Private sortorderenum sortdirection;
Private string searchid;
Public list getlist (){
Return list;
}
Public void setlist (list ){
This. List = List;
}
Public int getpagenumber (){
Return pagenumber;
}
Public void setpagenumber (INT pagenumber ){
This. pagenumber = pagenumber;
}
Public int getobjectsperpage (){
Return objectsperpage;
}
Public void setobjectsperpage (INT objectsperpage ){
This. objectsperpage = objectsperpage;
}
Public int getfulllistsize (){
Return fulllistsize;
}
Public void setfulllistsize (INT fulllistsize ){
This. fulllistsize = fulllistsize;
}
Public String getsortcriterion (){
Return sortcriterion;
}
Public void setsortcriterion (string sortcriterion ){
This. sortcriterion = sortcriterion;
}
Public sortorderenum getsortdirection (){
Return sortdirection;
}
Public void setsortdirection (sortorderenum sortdirection ){
This. sortdirection = sortdirection;
}
Public String getsearchid (){
Return searchid;
}
Public void setsearchid (string searchid ){
This. searchid = searchid;
}
}
Then, you only need to create an instance of this type and assign values to the required parameters through the set method.
Int page;
/*
* The page parameter in the request is the default current page number in displaytag. Of course, you can also use * tabletagparameters. sort_amount_page to indicate the current page number.
*/
If (request. getparameter ("page ")! = NULL &&! "". Equals (request. getparameter ("page "))){
Page = integer. parseint (request. getparameter ("page "));
} Else {
Page = 1;
}
Paginatedlist paginaredlist = new paginatedlisthelper ();
Paginaredlist. setpagenumber (PAGE );
// List data to be displayed on this page
List list = .......;
Paginaredlist. setlist (list );
// The total amount of data, which is automatically counted based on the total number and number of pages per page
Paginaredlist. setfulllistsize (...);
// If you only set these parameters, the remaining parameters will be the initial values assigned to your implementation class by default.
Finally, you need to add the instance to the request or session so that displaytag can know that this is an external page.
Request. setattribute ("pagelist", paginaredlist );
On the front-end, you only need to write like below.
<Display: Table name = "$ {pagelist}" id = "list" requesturi = "">
<Display: column property = "ID"/>
</Display: Table>
At first, I raised a question about how many pieces of data will be passed in each time. I thought this was unnecessary. I only needed to pass in the data for the first time, but I thought about it later, because the entire paging process is dynamic, it is very likely that the original data has changed while you flip the page. Therefore, it is necessary to input the total number of pages each time.