On Wed, 24 Apr 2002, Henri Yandell wrote:

> Not sure if I ever mentioned this. With an iterate tag, would the
> following be possible: [not got jstl to hand so inventing the names]
> 
> <c:iterate collection="myPhones" variable="col">
>   <c:preIterate><p>My phones are<ul></c:preIterate>
>   <li><c:get name="col"/></li>
>   <c:postIterate></ul>.</p></c:postIterate>
> </c:iterate>
> 
> I'm sure I'm doing lots of nasty things. But thought I'd ask.

Are you asking, "Can something like this be done in JSTL?"  The answer is
yes:

  <c:forEach items="${myPhones}" var="col" varStatus="s">
    <c:if test="${s.first}">My phones are<ul></c:if>
    <li><c:out value="${col}"/></li>
    <c:if test="${s.last}"></ul>.</p></c:if>
  </c:forEach>

This is useful because opening and closing <ul> tags won't print unless
the collection has at least one item.  This avoids empty <ul></ul>
elements (which normally display fine but are technically an error).

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


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

Reply via email to