Page flip control is required for displaying data in the form of a list, which is basically used in all modules of the project. To maximize the reusability and portability of page turning, the page turning logic is encapsulated in the form of components.
Analysis of paging Controller
Description:
The page flip controller is used to control the page flip content display and page flip operations on Web pages. By calling JSP, the page content is displayed on the web page. It supports multiple display modes and styles.
Design of paging Controller
Create a pageconfig class, a page class, And a pageview class for the paging controller respectively.
· Pageconfig. Java
Class
Class |
Pageconfig |
Statement |
Public class |
Description |
This class is used to save the page property values, such as the number of lines displayed on each page. |
Superclass |
|
Run |
|
Attribute description
Attribute |
Attribute description |
Definition |
[Pageconfig] |
|
|
| -- Page_size |
Page size |
Public static final int |
| -- Page_size_small |
Small page size |
Public static final int |
| -- Page_size_normal |
Normal page size |
Public static final int |
| -- Page_size_big |
Size of a large page |
Public static final int |
| -- Page_size_bigger |
Large page size |
Public static final int |
| -- Page_size_biggest |
Maximum page size |
Public static final int |
· Page. Java
Class
Class |
Page |
Statement |
Public class |
Description |
This class is used to save the page property values, such as the number of lines displayed on each page. |
Superclass |
|
Run |
Java. Lang. serializable |
Attribute description
Attribute |
Name |
Attribute description |
Data Type |
| -- Empty_page |
Blank Page |
Describe a blank page, that is, a page without content. |
Page Object |
| -- Objects |
Result set list |
Result set list |
Java. util. List or Java. util. Vector |
| -- Start |
Start Record Number |
Start record number, starting from 0 |
Positive Integers and 0 |
| -- End |
End Record Number |
End Record Number |
Positive Integers and 0 |
| -- Viewstart |
The start record number is displayed on the page. |
The start record number is displayed on the page, starting from 1. |
Positive Integer |
| -- Viewend |
Display the end record number on the page |
Display the end record number on the page |
Positive Integer |
| -- Hasprevious |
Whether the previous page is enabled or not |
Whether the previous page is enabled or not |
Boolean Value |
| -- Previouspagenumber |
Page number of the previous page |
Page number of the previous page |
Positive Integers and 0 |
| -- Hasnext |
Whether there is a next page Switch |
Whether there is a next page Switch |
Boolean Value |
| -- Nextpagenumber |
Page number of the next page |
Page number of the next page |
Positive Integers and 0 |
| -- Total |
Total number of rows |
Total number of rows |
Positive Integers and 0 |
| -- Totalpage |
Total number of pages |
Total number of pages |
|
| -- Currentpagenumber |
Current page |
Current page of Description |
Positive Integers and 0 |
| -- Pagesize |
Page size |
Number of lines on each page |
Positive Integers and 0 |
Constructor
Constructor |
Constructor description |
Parameters |
[Page] |
|
|
| -- Page (list l, int S, Boolean hasnext) |
Create page |
L number of records starting from S in the result set, starting from 0. Does hasnext have a next page switch? |
| -- Page (list l, int S, Boolean hasnext, int total) |
Create page |
L The number of records starting from S in the result set, starting from 0. Does hasnext have the number of rows in the switch total for the next page? |
| -- Page (list l, int S, int size, Boolean hasnext, int total) |
Create page |
L number of records starting from S in the result set, starting from 0. Size: number of rows on each page. hasnext: whether there is a switch on the next page. Total: Total number of rows. |
| -- Page (list l, int num, int size, int total) |
Create page |
L result set num current is the page size, number of rows on each page total number of rows of records |
| -- Page (list l) |
Create page without Paging |
L result set |
Method
Method |
Method description |
Return Value |
[Page] |
|
|
| -- Autocalculate () |
Automatically calculates the value of other attributes based on the current page, page size, and total number of rows. |
Private void |
| -- Getlist () |
Get result set |
Public list |
| -- Getviewstart () |
Obtain the start record number displayed on the page, starting from 1 |
Public int |
| -- Getviewend () |
Obtain the end record number displayed on the page |
Public int |
| -- Hasnextpage () |
Whether the next page exists |
Public Boolean |
| -- Haspreviouspage () |
Whether the previous page exists |
Public Boolean |
| -- Getpreviouspagenumber () |
Retrieve the page number of the previous page |
Public int |
| -- Getnextpagenumber () |
Obtain the page number of the next page |
Public int |
| -- Gettotal () |
Total number of records in the result set |
Public int |
| -- Gettotalpage () |
Obtain the total number of pages |
Public int |
| -- Getcurrentpagenumber () |
Obtain the current page number |
Public int |
| -- Getpagesize () |
How many rows of records per page are obtained |
Public int |
| -- Getstartofnextpage () |
Obtains the number of records starting from the next page in the result set, starting from 0. |
Public int |
| -- Getstartofpreviouspage () |
Obtains the number of records starting from the previous page in the result set, starting from 0. |
Public int |
| -- Getsize () |
Obtain the number of records on the current page |
Public int |
| -- Isempty () |
Checks whether the current page is blank. If the current page is blank, true is returned. Otherwise, false is returned. |
Public Boolean |
Pageview. Java
Class
Class |
Pageview |
Statement |
Public class |
Description |
By calling JSP, the page content is displayed on the web page. Images and buttons are not supported. Only text is supported. Usage: the JSP page is defined as follows: <% Pageview view = new pageview (request, out, page); %> display by default <% view. setvisible (true); %> display in the specified form <% view. setvisible (true,); %> |
Superclass |
|
Run |
|
Attribute description
Attribute |
Name |
Attribute description |
Data Type |
[Pageview] |
|
|
|
| -- Currenturl |
URL of the current page |
URL of the current page |
String |
| -- Style |
Style |
Style |
String |
| -- Usesquarebrackets |
Whether to add a [] Switch |
Add "[" and "]" on both sides of "Previous Page" |
Boolean Value |
| -- Page |
Web Page |
Web Page |
Page Object |
Constructor
Constructor |
Constructor description |
Parameters |
[Pageview] |
|
|
| -- Pageview (httpservletrequest request, jspwriter out, page )) |
Create a paging content |
The request client sends an out page to output the page web page. |
Method
method |
method description |
return value |
[pageview] |
|
|
| -- setvisible (Boolean visible) |
the page content is displayed by default. If visible is true, the page content is displayed. Otherwise, the page content is not displayed. |
Public void |
| -- setvisible (Boolean visible, int style, int order) |
the pagination content is displayed in the specified format. If visible is true, the pagination content is displayed. Otherwise, the pagination content is not displayed. |
Public void |
| -- setvisible (Boolean visible, Boolean usesquarebrackets, int style, int order) |
the pagination content is displayed in the specified format. If visible is true, the pagination content is displayed. Otherwise, the pagination content is not displayed. |
Public void |
| -- viewpage (Boolean usesquarebrackets, int style, int order) |
the page content is displayed in the specified form. Order is 0, indicating the complete form. displayed in the following order: Total: 18 pages: 2 current page: 1 per page: 10 go to the front and back pages of the home page to □□□order as 1, which indicates a concise form. It is displayed in the following order: 1/2order is 2 at the end of the front and back pages, complete Form 2, displayed in the following order: Total: 18 per page: 10 go to □□□□home page front page and back page 1/2 |
Public void |
Code of the paging Controller
You only need to encode the code based on the design of the paging controller.
Page flip Controller componentSource code
A) pageconfig. Java
B) page. Java
C) pageview. Java
SourceCode: Download Now
Call of paging Controller
The call of the paging controller is too simple. The call method is as follows:
· Import the paging controller package
<% @ Page import = "Java. util. list, Com. cwap. oa. controller. web. page. page, Com. cwap. oa. controller. web. page. pageview "%>
|
· Create a Page Object. Page. empty_page is a blank page.
Page page = page. empty_page;
|
· Create A pageview object
<% Pageview view = new pageview (request, out, page); %>
|
· Display page content:
Display by default
<% View. setvisible (true); %>
|
Display as specified
<% View. setvisible (true, 0, 1); %>
|
· Example of calling the paging Controller
The following is an example called in a JSP in the Forum section to display the list of all Forum sections. only part of the code is listed below:
<% @ Page Language = "Java" %> <% @ page contenttype = "text/html; charset = GBK" %> <% @ page import = "Java. util. list, Com. cwap. oa. controller. web. page. pageview, Com. cwap. oa. controller. web. page. page "%> <JSP: usebean id =" forumboardhelper "Scope =" page "class =" com. club8090.forum. forumboard. client. forumboardclienthelper "/> <% string TMP = request. getparameter ("pagenumber"); int pagenumber = 0; If (TMP = NULL | TMP. equals ("")) {Pagenumber = 1;} else {try {pagenumber = integer. parseint (TMP);} catch (Java. lang. nullpointerexception NPE) {pagenumber = 1;} catch (Java. lang. numberformatexception NFE) {pagenumber = 1 ;}} page = page. empty_page; // The page is initialized to page. empty_page blank page = forumboardhelper. getallforumboards (pagenumber); %>... <Table> <tr> <TD> NO. </TD> <TD> name </TD> <TD> description abstract </TD> </tr> <% list items = page. getlist (); If (items. isempty () {out. println ("<tr colspan = 3> no record exists </tr>");} else {int no; // The number of rows displayed on the page for (INT I = 0; I <items. size (); I ++) {forumboardmodel = (forumboardmodel) items. get (I); NO = page. getviewstart () + I; %> // display the record list <tr> <TD> <% = No %> </TD> <% = forumboardmodel. getname () %> </TD> <% = forumboardmode L. getsummary () %> </TD> </tr> <%} pageview view = new pageview (request, out, page); view. setvisible (true,) ;}%> </table>...
|