Wouldn't this be nice?

<c:join items='${employees}' delim=','/>

-----Original Message-----
From: Rick Reumann [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 13, 2004 11:09 PM
To: Tag Libraries Users List
Subject: Re: easy enough to write, but curious if it'll exist as part of
JSTL (forEach question)


Martin Cooper wrote the following on 10/13/2004 11:31 PM:
> I'm not sure what you mean by prepending or appending. What do you 
> want to prepend or append to (and why)?

Maybe I'm alone but it seems like I'm often having to display what I'm 
iterating over with forEach and usually I need something displayed 
'between' each iteration, such as a comma after each name if iterating 
over names.

Actually come to think of it, I'm being an idiot:) I'm so used to my Tag

where I pass in a collection and it basically does what you are doing 
below.

I guess I was thinking of giving forEach too much power with something 
like...

<c:forEach items='${collection}' property='someProperty'
    append=', ' ignoreLast='true'/>

Which might be..

<c:forEach items='${employees}' property='lastName' append=', ' 
ignoreLast='true'/>

Which would spit out a comma separated list of lastNames from the 
collection of Employee beans in employees.

Then again this is probably dumb to delegate that much to a forEach tag.

sorry been a long week and it aint over:)


> As for the "ignore" part, that's already there. If you use the 
> 'varStatus' attribute of <c:forEach>, you can then test 'status.first'

> and 'status.last'. For example:
> 
> <c:forEach var="item" items="${items}" varStatus="status">
>   <c:set var="csv" value="${csv}${item}"/>
>   <c:if test="${!status.last}">
>     <c:set var="csv" value="${csv},"/>
>   </c:if>
> </c:forEach>






-- 
Rick

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


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

Reply via email to