Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JSP and the fly likes jstl c:forEach Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jstl c:forEach" Watch "jstl c:forEach" New topic

jstl c:forEach

liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
Hello, I have 2 string arrays (contact and contactid) that I want to use in a jstl c:forEach to produce select options. So far I have the code below - it puts contactid values into options value, but now how do I open a reference to contact array AND insert the data into options text? Thank you in advance.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

Assuming that both arrays are the same length, and that the order of their entries correpsond, you could do this by traversing one array and using the index to grab references from the other.

But, I don't do it this way. When passing information to the JSP to contruct an options list, I use a Map implementation where the entry key is used as the option value and the entry value as the display text. That way it's a better abstraction, and you only have to traverse one construct.

For example:

If there is a chance that either entry could contain characters needed encoding, you would also use <cut> to encode the values as you did in your original post.

[Asking smart questions] [About Bear] [Books by Bear]
liliya woland
Ranch Hand

Joined: Apr 11, 2006
Posts: 134
This is great! Thanks a lot!
I agree. Here's the link:
subject: jstl c:forEach
It's not a secret anymore!