How can i paging into struts. I have a page where i want to display 20 records(out of >1200) at a time and then browse through one page to another.Can anyone publish some code to achieve this. I have already tried http://htmltable.yuriy-zubarev.com but it is taking me no where. Thanx
Hi Pagination is not a part of struts mean it wont provide any utility for this .u need to implement this in whatever format u want . There are many ways of implementing this pagination (but first decide up on the way in which u need pagination ie what are the things u r displaying like next,first,last,previous,total recorsd and all .......) then i will have 2-3 ways of implementing this 1. First store all the Results in session(If u feel that going to DB everytime is costly ) and then write a servlet(Action class which has a form with attributes like startRecord,EndRecord,totalRecords,pageactionString(like previous,next..)) and everytime store only that page records in an arraylist and iterate this in ur jsp . (If u want sample code for this i can help u out ) 2. There is some third party tool called iBATIS which provides ab api for this pagination .However this internally uses the same logic as in 1sr idea. com.ibatis.common.util.PaginatedList is the one which will help u .This is a part of Ibatis jar .u can get help from www.ibatis.com regarding this 3.There is a website called www.jsptags.com which provides a custom tag for pagination .This is the most simplest if u can succed in the confifurations given by them in thier website while using the TLD/Tag U go through all these and come out which is comfortable .i Feel 1st idea is easy if u can spare sometime in writing the logic
Paging... Ahh one of my favorites. While one of the solutions suggested earlier (Storing in Session) works for small result set paging but fails (in terms of scalability) for large number of rows (like you have - 1000+ rows). Below I have posted a solution that compromises neither performance nor scalability to achieve this. This is an extract of the complete solution presented in my book in Chapter 6 - "JSPTags integration with Struts to achieve scalable scrolling functionality with very large resultsets". Here are my suggestions based on my experiences for dealing Prev, Next functionality in JSPs with large scrollable result sets. There are two aspects to the Prev/Next functionality. The first is the display and the second is database/memory data retrieval I have found the following two third party (Both are free and one is open source) very helpful. They are: 1) Pager Taglib from jsptags.com 2) Display Tag from sourceforge (displaytag.sourceforge.net) Both of them are very good, very powerful and they can pretty much take care of paging, display, formatting issues. Coming to the second point - Data retrieval. A plain vanilla ValueListHandler that retrieves the data from the session does not cut it. By plain vanilla I mean "All the data is fetched at one shot and is iterated over at increments of 10 (say)" This approach works well if the number of rows is probably less than 100 When the row count goes well above 100 certain problems appear. Let us say 1000 rows were fetched. 1)The data has to be stored in HTTP Session. If each row takes up 500 bytes, you have a HTTP Session of size 500K. Multiply by that by number of users and you have run out of space.... 2)If a shared cache is used, then the size of the cache is reduced, but what happens if the data in cache is removed (based on LRU - Least recently used). 3)Keeping the database connection alive is not a solution either. Your solution has to address such questions. I have found it better to introduce a bit of database dependency in my solution (Standards freaks might frown on my solution, but sometimes rules have to be broken for getting even a decent performance) My solution is a hybrid of fetching database rows on demand and fetching all rows. All databases provide features to uniquely identify the current row. In Oracle it is the ROW_NUM In DB2 it is the ROW_NEXT When the first page is requested, fetch the data and track the ROW_NUM (or ROW_NEXT). A user who has requested the first page, will most certainly fetch more. Hence do a eager pre-fetch for the next three pages (say) after the first page is served (maybe asynchronously on a low priority thread - so your CPU has time for other higher priority tasks). This solution WORKS and works well. You can abstract the above implementation behind a spicy ValueListHandler and ValueListIterator (Core J2EEPatterns). (Sometimes plain-vanilla just doesnt cut it )
Now onto the Standards turf - Think about it - How many times in the lifetime of an application do you really port the database to a different vendor? Even if you port it, the portability we have sacrificed in the above solution is neglible and is trivial to change when migrating to a different database. Hope this helps. [ April 28, 2004: Message edited by: Srikanth Shenoy ]
Often when you want to expose paging through a list for users you must allow sorting by user selected field. I don't believe your method will work even if this field is fixed because the ROW_NUM sequence isn't generated per query, but is instead fixed for the table. Correct me if I am wrong. [ April 30, 2004: Message edited by: Sean Walker ]
Sean Walker<br />PMP, SCEA, SCWCD, SCJP
posted 16 years ago
Thanx all of you, especially Srikanth Shenoy i am working on ur tips.
hi, i m intersted with ur conversation...but i have a small problem...may be u can suggest me...,
i m facing probs with the struts in jps for add a record into a db using ejb in jboss server (liferay portals)...wat i want is i have placed all my set and get methods in forms and action classes check for submit button name...
i dont find any information it went into set method of my submit method...
and in action clas si m checking the name using "add Policy".equals(form.getPolicyAdd())... also i set up a server trace for in each of the submit get set and action forward...but nothing is going inot it...
can u suggest...any.... thz adv
Yeast devil! Back to the oven that baked you! And take this tiny ad too: