Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Pagination in Struts2

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am working on an application using Struts 2 and would like to display search results from Database in a pagination format.

I do get an arraylist from my action class which has multiple PERSON beans and each bean has fields like name, account, ssn etc...
Currently i am displaying all the results in one single page by extracting the bean objects from arraylist .

I have seen several posts to get this done using display tag but I am unable to get a clear cut idea as I am lame in terms of using Display tag and its dependencies.

I would really appreciate if someone could help me out in this regard.

Thanks,

Jalsa
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pawan,

i too have similar kind of issue, if you are able to solve that, can you please let me know the solution?


thanks in advance,

కిషోర్ కుమార్
 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Refer this link for configure display tag to your application...

Display tag library

Example of Display tag :- Display tag
 
Pawan Kalyan
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link Nishan.

I have been working to get that done using the Dipslay tag framework but i am confused how to use it with Struts 2.

i am using

<display:table id="data" name="arraylist" requestURI="Search.action" pagesize="10" >
<display:column property="account" title="Account ID" sortable="true" />
<display:column property="fName" title="First Name" sortable="true" />
<display:column property="lName" title="Last Name" sortable="true" />
</display:table>

I will get arraylist from session attribute. Arraylist has number of Person beans based on the resultset size.
I will store all the person beans into this arraylist and set in a session attribute which i retrieve in this jsp and display.

My person bean just has 3 fields account, fName and lName with getter and setter methods ().

I have even tried this without using requestURI="Search.action" in the display tag, it didn't work either.

Like i said, i am using Struts 2, so i am confused to work on this pagination issue.

If you need any additional information i can try to explain in detail, but i hope this would have given you a rough picture of my situation.

Thanks,
Pawan
 
Pawan Kalyan
Ranch Hand
Posts: 34
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey i got the solution.. Its pretty easy. I was stuck at naming conventions which the display tag will expect.

<display:table name="sessionScope.arraylist" requestURI="Search" pagesize="10" >
<display:column property="firstName" title="First Name" sortable="true" />
<display:column property="lastName" title="Last Name" sortable="true" />
</display:table>

Person bean should have fields like firstName , lastName. Do not use fields like fName, lName

The arrayList i am using in the display tag is set as a session attribute in the action class , and the requestURI should be the path to your action class. In my case its "Search".

You can see the format of jsp from the below link.

http://www.vaannila.com/struts/struts-example/struts-pagination-example-1.html

And add all the required libraries into the lib folder, specially the displaytag.tld and display-tag.jar , you can download from below link

http://displaytag.sourceforge.net/11/

Let me know if you have any doubts. I can help you if its my scope

Thanks,
Pawan Kalyan


 
a kishore
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you verymuch nishan and pawan for your support... i try to display but now im getting this error: "Nothing found to display.". i will try again and let you know.

thank you again,

kishore
 
Pawan Kalyan
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even i got the same error.

Then try to remove all the display:column inside the display tag..
then you can see all the data.

you will get that error because, the bean variable naming is not compatible with the Display tag conventions.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I´m new programig Struts2.
I´got a problem, with displayTag, I can see the elements and I try to pagin but every page have the same info in the columns, can clink on the page 2 or 3 o last but the info no change.
If I change the value of pagesize i can see more elements, so I think that displayTag always write the first elements.

<display:table name="organismos" id="organismos" export="false" defaultsort="" defaultorder="ascending" partialList="true" sort="external" requestURI="organismos_doBusqueda.action" size="size" pagesize="10" excludedParams="*">
<display:column property="CODORG" headerClass="A_left" class="A_left" title="Código" maxLength="40" sortable="true" sortName=""></display:column>
<display:column property="NOMBRE" headerClass="A_left" class="A_left" title="Nombre" maxLength="40" sortable="true" sortName=""></display:column>
<display:column property="DESCRIPCION" headerClass="A_left" class="A_left" title="Descripción" maxLength="40" sortable="true" sortName=""></display:column>
</display:table>

Have i do something more in the Action class?? I´ve got setters and getters... Need something about request o session ?

All examples i´ve read make it so easy so i don´t no why doesn´t work

Thanks a lot
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pawan,
I am also trying to get done the pagination in struts 2 but I am getting error...

java.lang.NoClassDefFoundError: Could not initialize class org.displaytag.tags.TableTag

Please help....

Thanks in advance....
 
Greenhorn
Posts: 16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vishall,

This problem is related to jar file, so verify your library for display tag.
you can download updated library from here.
 
Vishalll Kshirsagarrrr
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ravi kr wrote:Hi Vishall,

This problem is related to jar file, so verify your library for display tag.
you can download updated library from here.



Hi Ravi,

Really appreciate your help.....I got solved my problem by adding new JAR files....
Thanks...and hope you will help me going forward.....

- Vishal.
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!