Announcement Announcement Module
No announcement yet.
jstl and accessing collections inside hibernate object Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • jstl and accessing collections inside hibernate object

    I'm using spring together with hibernate.
    I just started to switch to jstl from plain jsp.
    My problem is that I can't figure out how to access a collection inside a hibernate object:

    <c:out value="${}"/>
    <c:forEach items="${articles}" var="article">
    <c:out value="${}"/>
    <c:forEach items="${article.descriptions}" var="descr">
    <c:out value="${descr}"/>

    If I try to acces one of the properties (e.g. there's simply no output.
    If I access the descr object like in the source above I get:
    org.hibernate.collection.PersistentMap$MapEntryPro [email protected]

    What am I doing wrong?

    P.S.: descriptions is a map with an Integer object used for the index.

  • #2
    For starters, you can't access 'article' outside the loop.

    <c:out value="${}"/>

    Can you verify that 'articles' is accessible using scriptlets, i.e. <% %> before using JSTL?

    Do you have the tag library declared at the top of the JSP page?


    • #3
      It's intentional to have outside of the loop to see that there actually is an object. The taglibs are declred in an include.jsp, sorry, I didn's paste my include line.
      Articles is accessible, if I put something like:
      <% pageContext.setAttribute("descr",(((Article)pageCo ntext.getAttribute("article")).getDescriptions()). get(new Integer(1))); %>
      I get the description of the current article and I can use it in a <c:out/> tag


      • #4
        Since article.descriptions is a Map, descr will be a Map.Entry (or in hibernate's case MapEntryProxy). This is the object returned when iterating over a Map. Therefore, you need to call either descr.key or descr.value to get the value you want.