Announcement Announcement Module
Collapse
No announcement yet.
jstl and accessing collections inside hibernate object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

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

    If I try to acces one of the properties (e.g. descr.name) there's simply no output.
    If I access the descr object like in the source above I get:
    org.hibernate.collection.PersistentMap$MapEntryPro xy@9a44f0

    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="${article.nr}"/>

    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?

    Comment


    • #3
      It's intentional to have article.nr 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

      Comment


      • #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.

        Comment

        Working...
        X