Struts logic:iterator for 2d array

Discussion in 'Java' started by Trevor, Apr 2, 2008.

  1. Trevor

    Trevor Guest

    Hi,

    I am using Struts 1.3 with Hibernate. If I run a simple HQL query in one of
    my data access objects (e.g. "from users as u"), this returns a list to my
    actionform which I can iterate through in my jsp as follows:

    <logic:iterate id="usersForm" name="usersForm" property="allusers"
    scope="request">
    <bean:write name="usersForm" property="firstname"/>
    <bean:write name="usersForm" property="lastname"/>
    </logic:iterate>

    The above works fine. However when trying to run a query that joins two
    tables together (e.g. "from users as u inner join u.addresses as a") this
    returns a 2D list in the format:

    Element 0
    User
    Address
    Element 1
    User
    Address

    Which I cannot use in my jsp as the <logic:iterate> is iterating over the
    top-level elements and not the user/address objects. I think I need to have
    nested <logic:iterate> tags but not sure of the syntax or how this affects
    my actionform.

    Any help of guidence on this would be very much appreciated.

    Thanks
    Trev
    Trevor, Apr 2, 2008
    #1
    1. Advertising

  2. Trevor

    Danno Guest

    On Apr 2, 8:51 am, "Trevor" <> wrote:
    > Hi,
    >
    > I am using Struts 1.3 with Hibernate. If I run a simple HQL query in one of
    > my data access objects (e.g. "from users as u"), this returns a list to my
    > actionform which I can iterate through in my jsp as follows:
    >
    > <logic:iterate id="usersForm" name="usersForm" property="allusers"
    > scope="request">
    > <bean:write name="usersForm" property="firstname"/>
    > <bean:write name="usersForm" property="lastname"/>
    > </logic:iterate>
    >
    > The above works fine. However when trying to run a query that joins two
    > tables together (e.g. "from users as u inner join u.addresses as a") this
    > returns a 2D list in the format:
    >
    > Element 0
    > User
    > Address
    > Element 1
    > User
    > Address
    >
    > Which I cannot use in my jsp as the <logic:iterate> is iterating over the
    > top-level elements and not the user/address objects. I think I need to have
    > nested <logic:iterate> tags but not sure of the syntax or how this affects
    > my actionform.
    >
    > Any help of guidence on this would be very much appreciated.
    >
    > Thanks
    > Trev


    I don't know how much help you will get, since people have started
    using some modern web frameworks, and Struts has also evolved from
    1.3. Try to nest the logic:iterate tags yourself and see if that
    works. You can also look into using JSTL to include in your Struts
    package which definitely provides the nesting capability. If you are
    doing a greenfield project then very much consider a modern web
    framework like Seam, Grails, Wicket, or Struts 2.0.
    Danno, Apr 2, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Hornsby
    Replies:
    4
    Views:
    7,068
    Sudsy
    Sep 24, 2004
  2. Hendrik Maryns
    Replies:
    18
    Views:
    1,420
  3. greg
    Replies:
    6
    Views:
    454
    Dietmar Kuehl
    Jul 17, 2003
  4. Replies:
    6
    Views:
    643
    Jim Langston
    Oct 30, 2005
  5. spike
    Replies:
    8
    Views:
    1,463
    Steve Holden
    Feb 9, 2010
Loading...

Share This Page