Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring MVC Pagination

 
laura mccord
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the best way to implement pagination yet maintaining the Spring MVC methodology? Also, the dataset will not be coming from a database, it will be a hashmap that is set via the controller. Does anyone have any suggestions?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Application Frameworks forum.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, We do have dedicated Spring Forum.
Stay updated
 
laura mccord
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh, I'm sorry. Can my topic be moved there please?

Many Thanks.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
laura mccord wrote:What is the best way to implement pagination yet maintaining the Spring MVC methodology? Also, the dataset will not be coming from a database, it will be a hashmap that is set via the controller. Does anyone have any suggestions?

Thanks.


You mean to say it would fetch the data from database for only time?
 
laura mccord
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, my code is a listing of files/folders that are contained in a given directory path, so a database is not involved. But, once I retrieve all the contents load it in a HashMap, my controller sends the hashmap to my jsp page. I've seen so many examples that are using a database but I haven't seen anything where it's just a list or hashmap. So, I was wondering if this has been done before so I don't have to recreate the wheel.

Thanks
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to check Display Tag.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the PagedListHolder class. This is a way to get the data and have a page size and sorting.

Mark
 
laura mccord
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestions.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
laura mccord wrote:Thanks for the suggestions.

Just curious, how did you apply the pagination?
 
laura mccord
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I actually haven't completed yet.I got sidetracked and I need to accomplish one more thing before I start messing with layout. I was just trying to get suggestions so I know what to start researching. I'll definitely post my result once I finish this step.

Thanks
 
Rahul Mishra
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used the DisplayTag earlier. If you google the forums you will find that it has been used with Spring MVC quite a bit.


Just download the sample WAR from display tag team , and see if the level of pagination supported in the examples suits your requirements (they have many examples showing various levels of customization to the tag).

What i liked about the tag is that it accepts a partial list (only what is to be displayed on the page) , this is a huge gain in terms of memory.

Check it out..
 
laura mccord
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I installed the display tag jar in my webapp and I'm trying to use it correctly. I noticed first thing that I'm able to get my data from the hashmap but it's not building the columns/rows correctly.



Say I want the following to output:

NAME SIZE TYPE
Documents 12 Folder
Desktop 10 Folder
Pictures 9 Folder
Music 23 Folder

Instead, I'm getting the following output using the code snippet above:

NAME SIZE TYPE NAME SIZE TYPE NAME SIZE TYPE NAME SIZE TYPE
Documents 12 Folder Desktop 10 Folder Pictures 9 Folder Music 23 Folder
Documents 12 Folder Desktop 10 Folder Pictures 9 Folder Music 23 Folder
Documents 12 Folder Desktop 10 Folder Pictures 9 Folder Music 23 Folder
Documents 12 Folder Desktop 10 Folder Pictures 9 Folder Music 23 Folder
Documents 12 Folder Desktop 10 Folder Pictures 9 Folder Music 23 Folder

What am I doing wrong?

Thanks.


 
laura mccord
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ugh, I finally got it after during trial and error:

This is what I was supposed to code:



My problem was that I was still trying to use my old jstl logic of traversing the HashMap and using this method for display:tag . But, display tag is much simpler.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic