This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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 ]
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"
Joined: Jan 10, 2005
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
Joined: Jul 04, 2004
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.
Joined: Jan 10, 2005
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 ]
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 ]
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 ]
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.