This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes How to display  ArrayList in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to display  ArrayList in JSP" Watch "How to display  ArrayList in JSP" New topic
Author

How to display ArrayList in JSP

Vineela Devi
Ranch Hand

Joined: Dec 20, 2003
Posts: 191
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
Viswa
Greenhorn

Joined: May 17, 2004
Posts: 16
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

Joined: Dec 20, 2003
Posts: 191
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

Joined: May 17, 2004
Posts: 16
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
Pankaj Narang
Ranch Hand

Joined: Jun 07, 2004
Posts: 81
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
Kinjal Sonpal
Ranch Hand

Joined: Jun 06, 2003
Posts: 96
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
 
wood burning stoves
 
subject: How to display ArrayList in JSP
 
Similar Threads
passing values from ActionClass to jsp struts 1.1
How Do I Update An ArrayList in an ActionForm?
displat:table tag pls help me
problem in forms..
using <html:messages> tag