DisplayTag PaginatedList implementation

Source: Internet
Author: User

1. Write a PaginatedList class PaginatedListHelper

  1. Public class PaginatedListHelper
  2. Implements PaginatedList {
  3. Private int fullListSize; // The total number of records.
  4. Private List list; // List of each page
  5. Private int objectsperpage; // number of records per page size
  6. Private int pagenumber = 1; // current page number
  7. Private string searchid;
  8. Private string sortcriterion;
  9. Private sortorderenum sortdirection;
  10. Public int getfulllistsize (){
  11. Return fulllistsize;
  12. }
  13. Public void setfulllistsize (INT fulllistsize ){
  14. This. fulllistsize = fulllistsize;
  15. }
  16. Public List getList (){
  17. Return list;
  18. }
  19. Public void setList (List list ){
  20. This. list = list;
  21. }
  22. Public int getObjectsPerPage (){
  23. Return objectsPerPage;
  24. }
  25. Public void setObjectsPerPage (int objectsPerPage ){
  26. This. objectsPerPage = objectsPerPage;
  27. }
  28. Public int getPageNumber (){
  29. Return pagenumber;
  30. }
  31. Public void setpagenumber (INT pagenumber ){
  32. This. pagenumber = pagenumber;
  33. }
  34. Public String getsearchid (){
  35. Return searchid;
  36. }
  37. Public void setsearchid (string searchid ){
  38. This. searchid = searchid;
  39. }
  40. Public String getsortcriterion (){
  41. Return sortcriterion;
  42. }
  43. Public void setsortcriterion (string sortcriterion ){
  44. This. sortcriterion = sortcriterion;
  45. }
  46. Public sortorderenum getsortdirection (){
  47. Return sortdirection;
  48. }
  49. Public void setsortdirection (sortorderenum sortdirection ){
  50. This. sortdirection = sortdirection;
  51. }
  52. }

 

2. Write action

  1. .....................
  2. // Page number
  3. Int pagenumber;
  4. If (request. getparameter ("page ")! = NULL
  5. &&! "". Equals (request. getparameter ("page "))){
  6. Pagenumber = integer. parseint (request. getparameter ("page "));
  7. } Else {
  8. Pagenumber = 1;
  9. }
  10. Paginatedlisthelper pH = new paginatedlisthelper ();
  11. Try {
  12. // Query paging data
  13. List dataList = dao. msgList (conn, pageNumber, para );
  14. // The total number of records
  15. Int totalNum = dao. totalcount (conn, para );
  16. Ph. setFullListSize (totalNum );
  17. Ph. setList (dataList );
  18. Ph. setPageNumber (pageNumber );
  19. Ph. setObjectsPerPage (20 );
  20. // Data passed to displaytag table name = "requestScope. msgList"
  21. Request. setAttribute ("msgList", ph );
  22. If (conn! = Null)
  23. Conn. close ();
  24. } Catch (Exception e ){
  25. E. printStackTrace ();
  26. Log. error (MsgAction. class, e. getCause ());
  27. }

3. Problem:

The paginated url may be affected by the struts action, and the struts action that executes the previous action is called every time you click the flip link;

I found this information on the Internet, but I still haven't found a solution. Maybe it's all the bugs solved by displaytag;

My solution is: if the actoin corresponding to my table display page is list. do, and there is a new button on the page. The corresponding action is new. If the new button is created successfully, the page is directed to list. At this time, the url of the page is new. If the page is displayed, the new method will be executed again, so that another record is inserted into the database. My solution is to force the action to be modified. For example, if you do not return to the list page, instead, a return button is left to trigger js, window. location. href = "/list. do "; in this way, the list page is displayed, and the page turning url of displaytag is also list. do now

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.