This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jstl c:forEach

 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is great! Thanks a lot!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic