• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to display ArrayList in JSP

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In ActionClass i have an ArrayList which holds the dataObjects.(Data Object has no of fields like Name, Age, Qualification etc).How can i display all these fields in my JSP.

I had set the ArrayList to the form in the ActionClass.


Pls help me.

Thanks in Advance

Vineela
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
if the array list is a bunch of value from Java Bean. follow,
In action class
....
request.setAttribute("sendToJSP",arrayListObj);
...
In your jsp page
<bean:write name="sendToJSP" property="firstName"/>
<bean:write name="sendToJSP" property="middleName"/>
<bean:write name="sendToJSP" property="lastName"/>
if not bean,
use iterator and find the size using <bean:size/> and iterate continuously.
that's all
Viswa
 
Vineela Devi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

No, the ArrayList is not a bunch of value from javabean.Rather it is the result of the query which we run.

i.e In ActionClass when i call a method(which runs a query) in DAO, the return type is an ArrayList.

This is the ArrayList which I want to display in JSP

I think now it is clear.

Regards
Vineela
 
Viswa
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In Action class
...
request.setAttribute("sendToJsp",arrayListObj);
...
In JSP page
...
<logic:iterate id="myIter" name="sendToJsp">
<bean:write name="myIter"/>
</logic:iterate>
For example,
Your arrayListObj contains firstname,midname,lastname,mailid.
here in jsp page logic:iterate iterate the loop depends upon the size of the arraylist object.
So this 'll iterate 4 times according to our example.
bean:write gives values from that array list.
Try this.
Regards,
Viswa
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

U have told the the arraylist contains the dataobjects from the query.So it may conatain many objects .

There r Three ways to disaply them on JSP

1:> Is simple iterate .But if u r using Struts framework it will disobey the laws of MVC. So this should not be done if Struts is used

2:> Use Logic:Iterate and print the values by bean:write but if the records r more it will dispaly all in single page that will be mess .

3:> Use Dispaly Which have the inbuild iterator in them and gives u the choice of no. of pages to be dispalyed per page.For theis taglib u have to give just the name of the list and it will iterate it for u.

Best Regards
Pankaj Narang
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vineela Devi Jakka:
In ActionClass i have an ArrayList which holds the dataObjects.(Data Object has no of fields like Name, Age, Qualification etc).How can i display all these fields in my JSP.

Please try this code and see if it gives what you requireHTH. Please post back for further query.

Thanks and regards,
Kinjal Sonpal
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic