Help with <c:forEach> and HashMap

L

Luis Pedro

Dear all,
I've an HashMap of type model <String, HahsMap>. The second HashMap
is of type <String, Object>.

I'm trying to iterate in this HashMap in my jsp page and things
like:
<c:forEach var="element" items="${model.products.product}">
<c:eek:ut value="${element.name}"/>

and

<c:forEach var="element" items="${model.products.provider}">
<c:eek:ut value="${element.name}"/>

But I want to access to product and provider simultaneously.
I tried
<c:forEach var="element" items="${model.products}">
<c:eek:ut value="${element.product.name}"/>
<c:eek:ut value="${element.provider.name}"/>

But this does not work:
javax.el.PropertyNotFoundException: Property 'product' not found on
type java.util.HashMap$Entry

Any idea on how to solve this?

Thanks very much in advance for your time.

Best regards,

Luis
 
V

vk02720

Dear all,
   I've an HashMap of type model <String, HahsMap>. The second HashMap
is of type <String, Object>.

   I'm trying to iterate in this HashMap in my jsp page and things
like:
<c:forEach var="element" items="${model.products.product}">
<c:eek:ut value="${element.name}"/>

and

<c:forEach var="element" items="${model.products.provider}">
<c:eek:ut value="${element.name}"/>

But I want to access to product and provider simultaneously.
I tried
<c:forEach var="element" items="${model.products}">
<c:eek:ut value="${element.product.name}"/>
<c:eek:ut value="${element.provider.name}"/>

But this does not work:
javax.el.PropertyNotFoundException: Property 'product' not found on
type java.util.HashMap$Entry

Any idea on how to solve this?

Thanks very much in advance for your time.

Best regards,

Luis

Looks like you are getting objects of type HashMap.Entry in 'element'
variable. You may have to use key and value (from Entry type) in some
way to get at what you want.
 
L

Luis Pedro

Hi there,
Thanks very much for the help. Great link. Anyway, just wanted to
share my solution.
Instread of the HashMap <String, HahsMap> with a second HashMap
of type <String, Object> I decided to just create a HashMap <Object,
Object> and then:
<table border=1>

<tr>
<c:forEach items="${model}" var="element">
<tr>
<td>${element.value.name}</td>
<td>${element.key.name}</td>
</tr>
</c:forEach>
</tr>
</table>

Hope it helps someone.

Best regards,

Luis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top