• 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

jstl c:forEach

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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
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 <c:out> to encode the values as you did in your original post.
 
liliya woland
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is great! Thanks a lot!
 
reply
    Bookmark Topic Watch Topic
  • New Topic