Usage of pager-taglib.jar Paging

Source: Internet
Author: User

1, put the pager-taglib.jar package in the project LIB;
2. Introduce the paging tag Library to the JSP page.
<% @ Taglib prefix = "PG" uri = "http://jsptags.com/tags/navigation/pager" %>
URI to copy from pager-taglib.jar \ META-INF \ taglib. TLD File
3. Specific Use
<PG: pager items = "1000">
</PG: pager>
The outermost side must be the tag, and the items is the total number of records.

<! -- The outermost side must be the pager tag, and the items is the total number of records, which are transmitted from the background. -->

<PG: pager url = "orgnization/Index" items = "$ {PM. total} "Export =" currentpagenumber = pagenumber "> // The URL is the action address, the total number of records in items, and the export can be renamed to the current page.
<PG: Param name = "parentid"/> // If parentid has a value, it will be passed behind the action as a parameter,
<PG: First>
<A href = "$ {pageurl}"> homepage </a>
</PG: First>
<PG: Prev>
<A href = "$ {pageurl}"> previous page </a> // Previous Page
</PG: Prev>
<PG: pages>

<% --
<S: If test = "% {pagenumber = currentpagenumber}">
<Font color = "red" >$ {pagenumber} </font>
</S: If>
<S: else>
<A href = "$ {pageurl}" >$ {pagenumber} </a>
</S: else>

-- %> // This section is commented out, because the test of struts2 must be specified in action for use. currentpagenumber is not specified in action, so it cannot be used; use the JSP label below to replace

<%
If (pagenumber = currentpagenumber ){
%> <Font color = "red" >$ {pagenumber} </font> <%
} Else {
%> <A href = "$ {pageurl}" >$ {pagenumber} </a> <%
}
%>
</PG: pages>
<PG: Next>
<A href = "$ {pageurl}"> next page </a> // next page
</PG: Next>
<PG: Last>
<A href = "$ {pageurl}"> last page </a>
</PG: Last>

</PG: pager>

Code in action

Public String index () throws exception {// display page

Int offset = 0; // The number of records that must be taken from the page.
If (request. getparameter ("pager. offset ")! = NULL ){
Offset = integer. parseint (request. getparameter ("pager. offset "));
}
Int pagesize = 10; // number of records per page

Long parentid = orginfo. getparentid ();
PM = orgmanager. findorgs (parentid, offset, pagesize); // PM is the pagermodel paging class, which has two attributes: Total (total number of records), list <> Datas (page result set)
If (parentid! = NULL ){
Orgnization org = orgmanager. findorg (orginfo. getparentid (); // obtain the parent institution
If (Org. getparent ()! = NULL ){
Orginfo. setppid (Org. getparent (). GETID (); // obtain the parent ID of the parent institution.
}
}
Return "Index ";
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.