-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Struts/JSTL iterate tag with mapped property
PostPosted: Fri Jan 23, 2004 5:34 pm 
Newbie

Joined: Fri Jan 23, 2004 5:31 pm
Posts: 5
I'm running into a problem iterating through maps because the Iterator.next() in net.sf.hibernate.collection.Map returns a MapEntryProxy instead of my object. Therefore, JSPs written to access my objects instead of a MapEntryProxy don't work too well. :)

What's the best way around this problem ? Is my only solution to encapsulate the iteration or ... ?!

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 5:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well this should just be a proxy so you can use it just like your normal object.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 5:45 pm 
Newbie

Joined: Fri Jan 23, 2004 5:31 pm
Posts: 5
gloeglm wrote:
Well this should just be a proxy so you can use it just like your normal object.


I can't.

Say my object has a getName() accessor, and my JSP refers to it as:

<bean:write name="mybean" property="name"/>

I get an exception because MapEntryProxy doesn't have a getName() method.

Am I just doing something very wrong ?

It all worked great when I used Sets, but this problem showed up with I switched to Maps...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 5:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well, this is a map entry as in Map.Entry which has two methods, getKey() and getValue(). Use it just as you would wenn calling map.iterator().next(). So do something like

Iterator iter = map.iterator();
while (iter.hasNext()) {
Map.Entry entry = iter.next();
myObject = entry.getValue();
}

In the JSTL you should be able to do seomthing like

<bean:write name="mapentry" property="value.name"> or something using the expression language. Been some time since I coded JSTL so I dont remember the exact syntax.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 9:41 pm 
Newbie

Joined: Fri Jan 23, 2004 5:31 pm
Posts: 5
Rewriting every property to be "value.property" does work.

That just seems horribly wrong for implementing an O/R layer that's supposed to be non-intrusive. :)

There really isn't a better way? Anyone? Anyone?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 11:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Please read the javadoc for java.util.Map.

hint: map.values().iterator() and map.entrySet().iterator() are completely different.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 24, 2004 1:26 am 
Newbie

Joined: Fri Jan 23, 2004 5:31 pm
Posts: 5
Thanks, I needed a kick in the head, it's been one of those days.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.