On Thu, 30 May 2002, Hughes, Matt wrote:

> 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:

In general, you can "spread out" the while loop just as you're trying to
do; doStartTag() returns SKIP_BODY or EVAL_BODY_INCLUDE (or
_BUFFERED) depending on whether the loop should proceed or not.  In other
words,

  while(c)

becomes

  if (!c)
    return SKIP_BODY

and so forth.

That's the generic answer.  I have two more specific thoughts for you,
though:

 - JSTL offers a LoopTagSupport abstract class that simplifies the
   development of loop tags.  It essentially lets you write an
   iteration tag by simply supplying next() and hasNext() methods,
   much as with Iterator.  This support class might be convenient for
   what you're trying to do.

 - You might be interested, moreover, in using JSTL's database support,
   and its <c:forEach> tag to loop.  Using JSTL's database support,
   you end up with more explicit, obvious "loop" constructs than
   a <resultset> tag implicitly loops.

> 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>

This problem goes away if you use JSTL's support; you can use the
expression language to refer to data from within an attribute value.

Hope that helps!

-- 
Shawn Bayern
"JSP Standard Tag Library"   http://www.jstlbook.com
(coming in July 2002 from Manning Publications)


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

Reply via email to