• 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

ArrayList

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Can somebody help me with an arraylist? My problem is I have about 80 things I need to list in a drop down menu and instead of hard coding it, I want to list these items using a for loop or is it possible to do this? If you can get me started I would be most greatful.





____________________________________________________________
[ January 10, 2005: Message edited by: Alice Senter ]
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think this would be the right place for this question. Nevertheless. Is it that you have a set of 80 strings in an ArrayList already? If so, then you could use the following code skeleton to set up the drop-down list menu:

 
Alice Senter
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the JSP forum and I'm doing this in a JSP. No I'm trying to list times from 12:00 pm to 12:00 am.



This isn't working but I'm at this point trying to make this work.


_________________________________________________________________
[ January 10, 2005: Message edited by: Alice Senter ]
 
Vijayendra V Rao
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean to say that your List contains the times as String objects? If your data is in a List and you need to sequentially access them, then u will need to use an iterator.

Tell me first, what exactly does your List contain? Are they Strings (I mean, they will definitely be Objects but what objects did you put them in as?)? Because if you have put them as Strings then you can retrieve Strings back (by using a cast) and print them out.
 
Alice Senter
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well basically I want to print out the times by creating a loop so I don't have to hard code 12:00 am to 12:00 pm. Later I want to list these times in 15 minute incriments so that comes to 96 times that I will have to hard code. So I want to create an arraylist and a for loop to list the times in a drop down menu. The times are not coming from a database but I'll need to get an int value (time ID) and a string (time 1:00pm) from the times to pass to the database.




_______________________
[ January 10, 2005: Message edited by: Alice Senter ]
 
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
If we assume that you have a List as a scoped variable named timeOptions, and that the values to be passed to the DB are the List indexes, then you could do this using the JSTL with something along the following lines:



This assumes you are operating in a JSP 2.0 environment.
[ January 10, 2005: Message edited by: Bear Bibeault ]
 
Alice Senter
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear

But I would rather stick to the way I'm trying to do it. At this point I would rather stay away from custom tags. There has to be away to print these times out using a array list and a for loop well I guess there is, is there?




___________________
[ January 10, 2005: Message edited by: Alice Senter ]
 
Bear Bibeault
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
The JSTL is a standardized tag set for JSP (that's what the S stands for). It is the preferred method of looping in a JSP.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Alice Senter:
[QB]Thanks Bear
But I would rather stick to the way I'm trying to do it. At this point I would rather stay away from custom tags. There has to be away to print these times out using a array list and a for loop well I guess there is, is there?
[QB]



As Bear said, this IS the normal way of doing it and doesn't involve anything that's not standardised.

And it IS a for-loop so it's exactly what you want.
 
Your mother was a hamster and your father was a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic