Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

displaying ArrayList results in jsp page  RSS feed

 
chintu reddy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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.
 
Frank Kellinghusen
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!