File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
laura mccord
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always code to Java Reflection.

Mark
 
laura mccord
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic