You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Brian Daddino <br...@opus-ism.com> on 2008/07/22 17:20:47 UTC

Using the iterator to list results from a hibernate join

Hi,

I'm new to Struts 2.   I have searched the web but can not find anything
on my issue.

 

Basically I have a many to 1 relationship between 2 objects, Contact and
contactmethod (contact being the 1).  

Contacts objects contain a person's name and contact method is basically
just a name value pair. 

What I would like to display is the name and all contactmethods in 1
list....

Example:

John Smith phone 555-1212

John Smith fax 555-2323 <ma...@something.net> 

 

My hibernate query returns a list.

List l = session.createQuery("FROM Contact c left join
c.contactmethodses").list();

 

It seems that the way the join is handled is to make each list entry
actually be an array of 2 objects (a contact object and a contactMethod
object).  

 

Here is my JSP code...

 

<s:iterator value="contacts"  status="status">

        <tr>

            <td class="nowrap"><s:property /></td>

            <td class="nowrap"><s:property value="<what do I put in
here???"/></td>

        </tr>

 

    </s:iterator>

 

I will get the correct # of lines, however, I can not figure out how to
read the values out of the array in this list item.

Using <s:property /> will get me gui.Contact@1b08cf3 but how do I
actually read properties of that object  or the 2nd object (contact
method)?  

What do I put in the value field of my property tag?

 

Thanks,

Brian

 


This electronic transmission may contain PRIVILEGED AND CONFIDENTIAL information intended only for the addressee(s).  If you are not the intended recipient, or the employee or agent responsible for delivery to the intended recipient(s), please note that any review, dissemination, use, distribution or copying is strictly prohibited.  If you receive this in error, please notify the sender immediately, destroy any paper copies and delete it from any computer.  Thank you.


Re: Using the iterator to list results from a hibernate join

Posted by Dave Newton <ne...@yahoo.com>.
--- On Tue, 7/22/08, Brian Daddino <br...@opus-ism.com> wrote:
> I'm new to Struts 2.   I have searched the web but can
> not find anything on my issue.

Did you look at the S2 documentation wiki? It answers these questions.

> What do I put in the value field of my property tag?

Here's some pseudo-code based loosely on your requirements.

<s:property "contact.name"/>
<s:iterator value="contact.contacts">
  <s:property value="email"/>
  <s:property value="phone"/>
</s:iterator>

The contact is exposed by the action.

The <s:property.../> tags call, in this example, getEmail() on each object being iterated over. An alternative way would be:

<s:iterator value="contact.contacts" id="aContact">
  <s:property value="#aContact.email"/>
  <s:property value="#aCotnact.phone"/>
</s:iterator>

I'd recommend looking over some of the basics on the S2 wiki.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org