File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Spring MVC: How do I display the Object elements/keys not the values? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring MVC: How do I display the Object elements/keys not the values?" Watch "Spring MVC: How do I display the Object elements/keys not the values?" New topic
Author

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

laura mccord
Ranch Hand

Joined: Feb 10, 2009
Posts: 108
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

Joined: Feb 05, 2001
Posts: 17260
    
    6

You can always code to Java Reflection.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
laura mccord
Ranch Hand

Joined: Feb 10, 2009
Posts: 108
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

Joined: Jan 10, 2002
Posts: 61768
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring MVC: How do I display the Object elements/keys not the values?