Ok, so I've got my nesting problem fixed (see below if interested) but I'm
still stuck on one thing.  I've got three nested tables:

Company (primary key: company_id)
        Addresses (primary key: address_id)
                Contacts (primary key: contact_id)

So...for each company there could be multiple addresses, and with each
address there could be multiple contacts.  My tags are set up as follows.

<ResultSet id="rs1" source="company" parameter="10001">
        <ResultSet id="rs2" source="address" parameter="10001">
                <ResultSet id="rs3" source="contact" parameter"">

As you can see I'm only selecting one company row on each page.  The
parameter for address ResultSet is the same as company, since it's all the
addresses for that company.  But the parameter for the contacts needs to be
dynamic.  For each address it needs to list all the contacts underneath it,
so it needs to know the address_id of it's parent.  Something like:
        <ResultSet id="rs3" source="contact" parameter="<column
rs="rs2">address_id</column>">

This doesn't seem to work.  Neither does just inserting regular variables
like

        <ResultSet id="rs3" source="contact" parameter="<%= address_id %>">

The tags and JSP seem to be evaluated at the same time so everything I put
in quotes for the parameter stays in quotes.  Any ideas?


-----Original Message-----
From: Hans Bergsten [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 30, 2002 2:06 PM
To: Tag Libraries Users List
Subject: Re: Nested Tag Libraries


Just adding to what Shawn said, you may also want to try a joined
query instead of repeatedly accessing the database. It should be more
efficient in most databases. With the JSTL actions, you can then
take care of the display details when you render the table instead:

   <sql:query var="addrs">
     SELECT * FROM Names, Addresses, Phone
     WHERE Names.Id = Addresses.Name_Id AND
       Addresses.Id = Phone.Address_id
     ORDER BY Names.Id, Addressed.Id
   </sql:query>

   <c:forEach items="$addrs.rows" var="current">
     <c:if test="${name != current['Names.Id']}">
       <c:set var="name" value="$current['Names.Id']}" />
       Name: <c:out value="${current.name}" />
     </c:if>
     <c:if test="${address != current['Addresses.Id']}">
       <c:set var="address" value="$current['Addresses.Id']}" />
       Address: <c:out value="${current.address}" />
     </c:if>
     Phone: <c:out value="${current.phone}" />
   </c:forEach>

Note that you may have to use an explicit column list in the SELECT
list instead of "*" and assign aliases to the Id columns in all tables,
and then adjust the names used in the rest of the example accordingly.
The syntax for aliases varies a bit between databases but many support
something like

   SELECT Names.Id AS Names_Id, Addresses.Id AS Addresses_Id ...

Hans

Hughes, Matt wrote:
> Ok basically I want to do something really simple but I'm not exactly sure
> how to do it with tag libraries.  I have three tables: name, address,
phone.
> Each name can have multiple addresses, and each address can have multiple
> phones.  So using plain old jsp it would look something like:
> 
> rs1 = "select * from names";
> while (rs1.next()) {
>     rs2 = "select * from addresses where name_id = names.id";
>     while(rs2.next()) {
>           rs3 = "select * from phone where address_id = addresses.id";
>           while (rs3.next()) {
>           }
>     }
> }
> 
> So that the output would look something like:
> 
> Matt Hughes
>     Address 1
>         Phone 1
>         Phone 2
>     Address 2
> etc...etc...
> 
> Yeah, it's really very pseudocode, but I think it's understandable.  So
I've
> created three generic tags: connection, resultset, and column.  How do I
> recreate those kinds of nested while loops using tags.  I almost want to
put
> the beginning of the while loop in the doStartTag and the end bracket in
the
> doEndTag...if only it were that easy.  Any suggestions on how I could make
> the tags work to something like below:
> 
> <Connection id="conn1">
>    <resultset conn="conn1" id="rs1">
>        <column rs="rs1">first_name</column>
>        <resultset conn="conn1" id="rs2">
>            <column rs="rs2">address_1</column>
>            <resultset conn="conn1" id="rs3">
>                 <column rs="rs3">phone_1</column>
>            </resultset>
>         </resultset>
>     </resultset>
> </connection>
> 
> 
> The other problem I'm having with this is how to pass the field_id from
the
> second table into the third tag.  Ideally it should look something like:
> 
> ...
>               <resultset conn="conn1" id="rs3" QueryParameter="<resultset
> conn="conn1" id="rs2">field_id</resultset>
>                       <column rs="rs3">contact name</column>
>               </resultset>
> 
>
----------------------------------------------------------------------------
--
> Notice: This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that
may be confidential, proprietary copyrighted and/or legally privileged, and
is intended solely for the use of the individual or entity named on this
message. If you are not the intended recipient, and have received this
message in error, please immediately return this by e-mail and then delete
it.
> 
>
============================================================================
==
> 
> 
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
> 


-- 
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
JavaServer Pages        http://TheJSPBook.com


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains information of 
Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, 
proprietary copyrighted and/or legally privileged, and is intended solely for the use 
of the individual or entity named on this message.  If you are not the intended 
recipient, and have received this message in error, please immediately return this by 
e-mail and then delete it.

==============================================================================


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to