• 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

displaying ArrayList results in jsp page

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.. I have a jsp page where I have to print "available shows" for a given "movieId". "movieID"is passed from jsp page to servlets and that gets an ArrayList of Shows object from database. This shows object has date and time as fields. Now I want to print these results as per date.. I mean,

my arrayList is Like ([date1,sh1], [date1,sh2], [date1,sh3], [date2,sh1], [date2,sh2].....)

and I want to print it like..

date1 sh1 sh2 sh3
date2 sh1 sh2 sh3
date3 sh1 sh2 sh3

Can anyone suggest me any startup idea about how to proceed?

thanks in adv.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First your list must be available to your JSP. You could put the list into an appropriate scope as an attribute.
Then your JSP needs to display the values. First thing that comes into my mind is using EL with the [] operator.
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If and only if you put your show beans in the ArrayList, ordered by date, you could proceed in the following way.

1) You loop in your arraylist and use a variable buffer for the current date, called, for example, currentDate.

2) Each step of the loop you test whether the date of the actual index of the list equals currentDate or not.

3)If it does you print the corresponding time.

4) If not:
a) You update your current date buffer, currentDate with the one of the show bean at the actual index
b) You write a new line and start printing the date and the time of the show bean at your actual index

I hope i was clear and understood what you want to do.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd pre-sort the data before getting to the JSP.

You could determine all the unique dates, and then create a Map that associates the movies items with each unique date: Map<Date,List<Movie>>

This construct would be easy to iterate over within the JSP using nested <c:forEach> tags.
 
reply
    Bookmark Topic Watch Topic
  • New Topic