aspose file tools*
The moose likes Struts and the fly likes nested:iterate with hibernate objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "nested:iterate with hibernate objects" Watch "nested:iterate with hibernate objects" New topic
Author

nested:iterate with hibernate objects

alan wamser
Ranch Hand

Joined: Jan 30, 2006
Posts: 41
I have two hibernate objects (JobApplication, JobApplicationComments). It's a one-to-many relationship. The JobApplication contains the following.

private Set jobApplicationComments = new HashSet(0);.

The JobApplicaitonComments has the following fields...

private Long commentsId;
private JobApplication jobApplication;
private String comments;
private Date createdDate;
private String createdBy;


I retreive a JobApplication from the database and can verify this using log4j. However when I use the nested:iterate I get the following error.

javax.servlet.ServletException: Invalid argument looking up property jobApplicationComments[0].comments of bean jobApplication

Here is the code from the jsp...

<nested resent name="jobApplication">
<nested:root name="jobApplication">
<nested:write property="firstName"/> <nested:write property="lastName" /><br>
<nested:iterate property="jobApplicationComments" >
<nested:write property="comments" />
</nested:iterate>
</nested:root>
</nested resent>

Here is the code in my action that I used to verify the correct application and comments.

Iterator myComments = (Iterator)jobApplication.getJobApplicationComments().iterator();

while (myComments.hasNext()) {
JobApplicationComments comments = (JobApplicationComments) myComments.next();
logger.debug("Comments: " + comments.getComments());
}

What am I missing???
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
What you're missing is an indexed getter for jobApplicationComments. When you use an indexed property in your JSP such as jobApplicationComments[0].comments , Struts must be able to get a single JobApplicationComment for a given index.

This becomes problematic for you, because you are storing these objects in a HashSet.

Here's a quote from the HashSet javadoc:

This class implements the Set interface, backed by a hash table (actually a HashMap instance). It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.


Since a HashSet does not have any concept of ordering and objects are not retrieved in any order, I can't think of a way to create an indexed getter for this object.

You may want to consider changing this collection to an implementation of the java.util.List interface, since implementors of this interface have a get(int index) method.


Merrill
Consultant, Sima Solutions
 
wood burning stoves
 
subject: nested:iterate with hibernate objects