• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Spring MVC: How do I display the Object elements/keys not the values?

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have passed an Object (not a hashmap) to a jsp page. I want to display the elements of the objects not only the values of the elements. How do I do that?

There are conditions that I want to perform based on the key but since its an object and not a Hashmap of objects I can't loop through the object. At least I don't think so...

For example... If I have a Object called AddressBook and I pass one instance of AddressBook to a jsp page I want to display the labels (Phone, Email, Address, City, State, etc,,,) dynamically.

I can access the information directly like ${addressbook.email} without a loop to display the value but I'd like to display the keys.

Thanks.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can always code to Java Reflection.

Mark
 
laura mccord
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the tip.

I think I posted this in the general forum because I later thought perhaps this wasn't the right category to post this issue...oops! I got a soft reprimand
 
Sheriff
Posts: 67694
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
If you'd like to have this moved, just ask one of the mods -- please don't duplicate post.

Personally, I'd use a Map before resorting to reflection (which would require using scriptlets -- a really really bad idea). It'd be fairly easy to populate a Map from the bean data, and forward the Map along to the JSP. And using a LinkedHashMap would even let you specify order.
 
reply
    Bookmark Topic Watch Topic
  • New Topic