Experience 15--Custom Paging labels

Source: Internet
Author: User
Tags prepare

1. Customize the paging label

• Pagination labels are used in the following ways:
<q:pager pageno= "The current page number" pagesize= "the number of records to be displayed per page" recordcount= "Total Records" url= "the URI to jump"/>. By passing the label to the current page number, the number of records to display per page, the total number of records, and the URI to jump, the tag can generate the HTML element for the page.

• Label Handling class

• This tag can generate all page-flipping elements simply by specifying the value of the property, so this tag does not require a body and can be directly inherited from the TagSupport class: public class Pagertag extends TagSupport {...}

• Then define 4 attributes for this tag, giving them a setter method so that when using the label, the value is passed in from the outside.

• The most important logical implementation is in the doStartTag () method, which first calculates the total number of pages by Total records and the number of records to display per page:
int PageCount = (recordCount + pageSize-1)/pageSize; Generally do not use this method to calculate the total number of pages, commonly used more friendly points of the algorithm: int pagecount = Recordcound (Total records)% PageSize? Nowpage (Total pages): nowpage+1;

write the StringBuilder instance to output to the response.

• Generate all request parameters obtained in the Request object as hidden table fields (<input type= "hidden" >) into a form:

• Generates HTML elements for paging. This section of logic is a little more complicated.

• Generate "total number of records and total pages"

• Whether you want to display the logical processing of the previous page hyperlink.

• If the total number of pages exceeds 5 pages, show "..."

• Display processing of the current page and its adjacent pages

• If the total number of pages is more than 2 pages than the current page, show "..."

• Do you want to display the logical processing of the next page hyperlink

• Describe the label information in the tag library descriptor file

• Use the paging label on the page

• Refer to the Tag library description file with the taglib directive:
<%@ taglib uri= "Http://blog.csdn.net/qjyong/tags/pager" prefix= "Q"%>

• Prepare a few styles for the paging label to make the page-flipping elements more attractive:

• Displaying data in code snippets

• Paging Tab calls

• Create a Testpagertagservlet servlet to prepare test data, prepare parameter values for the paging label, and forward to the test page.

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.