How can I go through a Set in JSP? (Hibernate Associations)

Posted by Parris on Stack Overflow See other posts from Stack Overflow or by Parris
Published on 2010-04-09T07:41:39Z Indexed on 2010/04/09 7:43 UTC
Read the original article Hit count: 241

Filed under:
|
|
|
|

Hi All, So I am pretty new to JSP. I have tried this a few ways. Ways that would make sense in PHP or automagicy frameworks... I am probably thinking too much in fact...

I have a hibernate one to many association. That is class x has many of class y. In class x's view.jsp. I would like to grab all of class y, where the foreign key of y matches the primary key of x and display them. It seems that hibernate properly puts this stuff into a set. Now, the question is how can I iterate through this set and then output it's contents...

I am kind of stumped here. I tried to write a scriptlet,

<%
java.util.Iterator iter = aBean.getYs().iter(); // aBeans is the bean name
// getYs would return the set and iter would return an iterator for the set
while(iter.hasNext) { 
   model.X a = new iter.next() 
%>
   <h1><%=a.getTitle()%></h1>
<%
}
%>

It would seem that that sort of thing should work? Hmmmmmm

© Stack Overflow or respective owner

Related posts about java

Related posts about jsp