aspose file tools*
The moose likes JSP and the fly likes ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "ArrayList" Watch "ArrayList" New topic
Author

ArrayList

Alice Senter
Greenhorn

Joined: Jan 10, 2005
Posts: 4
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 ]
Vijayendra V Rao
Ranch Hand

Joined: Jul 04, 2004
Posts: 195
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:



Vijayendra <br /> <br />"The harder you train in peace, the lesser you bleed in war"
Alice Senter
Greenhorn

Joined: Jan 10, 2005
Posts: 4
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

Joined: Jul 04, 2004
Posts: 195
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

Joined: Jan 10, 2005
Posts: 4
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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61770
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alice Senter
Greenhorn

Joined: Jan 10, 2005
Posts: 4
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61770
    
  67

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.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
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.


42
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArrayList