Thursday, November 30, 2006

Struts: Paging and Sorting with Displaytag

In the previous post, I described the use of Displaytag to implement paging in a simple JSP. In this example, I describe the use of Displaytag to implement sorting along with paging in Struts.Skip to Sample CodeIn this example, we take a single input field, which is used to filter the employee list based on the minimum salary. Follow these steps to implement the solution.

Please refer to the previous posthttp://java-x.blogspot.com/2006/11/pagination-with-displaytag.htmlthis handles simple pagination without struts. I wouldn't advise you to put a lot of logic in you JSP. However if you don't want to use displaytag (like when the dataset is too large), then you have to consider using hibernate's setMaxResults(int maxResults) and setFirstResult(int firstResult) methods of the Query interface. The example in this post and the previous one use hibernate to fetch data. I will see if I can post an example of this as soon as I get some free time.

Implementing the whole thing yourself (without hibernate) will take too much time and might not be bug free.

I was just wondering if you'd had any odd problems. In particular, I've got most everything working, except that, at the top and bottom of the table, it says "x items found, displaying y to z". The problem I keep having is that y and z are always 1 and 25 (unless the page shows only fewer records, in which case the second number changes to something which is still wrong. I thought maybe it was a matter of setting "offset", but that results in even weirder behavior.

Using DisplayTag pagination feature, do I have to always store the list in the session? My list can be womewhat large and I would like to get a page of data everytime they click on Next, Previous, First and Last links. Is this possible?

Hi Abhi,I am Srikanth, I am doing now pagenavigaton in jsp.I am not using Hibernet and struts. i am using netonomy framework.i had my total data as a array of objects in jsp.Now i want to display it by using paging.in my jsp.How can i use this displaytag for my applicaiton.my email id srikanth.scjp@gmail.com. Please help me for this

Hi,I am using a display tag for pagination in my JSP page. I have a checkbox field as one of the columns. I am using displayTagWrapper class to display my checkboxes. I also have pagination and sorting in the page.

The problem i have is, i will loose the status of the checkbox when i go to second page. If i select some of the checkboxes in page 1 and go to page 2 to select some more and if i come back, i loose all the selected checkboxes in page 1.

Is there a way where i could save my check boxes in session and its checked while i browse across pages and gets submitted all at once.

Can you pls tell me using your same example, I like to ask that if i have records more 10000 than it will be like load on session variable. Can you suggest me any caching method for same using same example. I will helpful for me..

I am using displaytag for pagination. Along with sorting problem, i have one more problem.I want to show checkboxes for a column. also i want to set then checked or unchecked on the basis of column value.

Can you give me a sample code for showing checkboxes using displaytag?

hi... i hv some problem .. my display tag have one column that have more than one field to be key-n such as textarea, text area, input value from calendar and radio button.. i wanna ask u, if i key-in in first page, how i carry that value to the next page.. there is Save function - allow user to save all record, in whatever page he edit...

Considering there are 2 users. they view thesame url with list of data (Using Displaytag pagination) that has 3 pages. when user1 is still at the 1st page and user2 added 5 records at thesame time. How can i update the data of user1 added by user2 when nextpage is clicked.

Hi,I am using a display tag for pagination in my JSP page. I have a checkbox field as one of the columns. I am using displayTagWrapper class to display my checkboxes. I also have pagination and sorting in the page.

The problem i have is, i will loose the status of the checkbox when i go to second page. If i select some of the checkboxes in page 1 and go to page 2 to select some more and if i come back, i loose all the selected checkboxes in page 1.

Is there a way where i could save my check boxes in session and its checked while i browse across pages and gets submitted all at once.

Hi I'm working with Struts using My Eclipse and MySQL.. Can u tell me the code for displaying a particular column from the database in combobox through jsp . I want both the java action coding and the jsp coding. can u help me with this..

The above link is good example for sorting and paging for a struts based web application but it is working only for independent page not in tiles. Any idea? please let me know at bhagat.rawat@gmail.com

Hi Abhi I am using displaytag in my application with struts-2 and it is working fine.But there are too many records in the DB so everytime it is fetching all records when the page links.could you please help me to do the external paging and sorting using displaytag in struts2.I searched in internet but i didnt get clear idea of how to implement it. Please help me to solve the issue.

I have a problem: when I change the page, the sorting by column is lost.

Example: I have two columns in my app (id, name), and originally, the query executed in the database is sorted by the column 'name' in ascending order. If I click on the column 'name' again, the sort will be done in descending order. The problem happens when I click to go to another page ... sort of reference is lost. How can I preserve it?

Need some help.I am actually using the displaytag export to excel option. I have numbers leading with zero's, while exporting to excel, it is formatted and leading zero's are removed. Is there any way I to prevent that?