This doesn't really address your suggestion specifically, but it might
be worthwhile to write your own custom tag that assumes that it's nested
within a logic:iterate and only evaluates it's body when it's not the
last iteration. That way you could write something like this in your
JSP:

<logic:iterate property="contacts" id="member"
type="example.ui.busobj.Member" indexId="memberNumber">
  <logic:write
property="member.name"/><mylogic:notLastIteration>,</mylogic:notLastIter
ation>
</ logic:iterate>

Which is more concise and communicates what you're doing more
accurately, IMO.

This tag shouldn't be hard to write...I'd take a crack at it, but I
don't know if I'd be allowed by the company to post to the list...we
still don't have a good policy regarding open source contributions :-(


Now that I think about it, it might be nice to have a whole library of
conditional tags for use within iterate:

 iterate:firstIteration
 iterate:lastIteration
 iterate:notFirstIteration
 iterate:notLastIteration
 iterate:even
 iterate:odd

Although, on the other hand, if the iterate tag is going to be
deprecated in favor of the JSTL forEach tag, then it may be better to
target that.
-- 
Tim Moore / Blackboard Inc. / Software Engineer
1899 L Street, NW / 5th Floor / Washington, DC 20036
Phone 202-463-4860 ext. 258 / Fax 202-463-4863


> -----Original Message-----
> From: Heath Chiavettone [mailto:[EMAIL PROTECTED]] 
> Sent: Tuesday, March 19, 2002 5:52 PM
> To: '[EMAIL PROTECTED]'
> Subject: Request for enhancement
> 
> 
> I've found that I'm starting to get the following pattern 
> throughout my jsps.
> 
>  
> 
> <bean:size property="contacts" id="numContacts"/>
> 
> <% Integer lastContact = new Integer(numContacts.intValue() - 1); %>
> 
>  
> 
> I'm mostly using this within an iterator to determine whether 
> I'm currently processing the last element of a collection as 
> is described below.
> 
>  
> 
>             <logic:iterate property="contacts" id="member" 
> type="example.ui.busobj.Member" indexId="memberNumber">
> 
>                         < logic:write 
> property="member.name"/><logic:lessThan 
> property="memberNumber" value="<%=lastContact.toString()%>">, 
> </logic:lessThan>
> 
>             </ logic:iterate>
> 
>  
> 
> I was wondering if it makes sense to add an additional 
> attribute to the size tag which controls whether the value is 
> a true size, versus the index of the last element (i.e. one 
> based versus zero based)?
> 
>  
> 
> Thanks for your feedback,
> 
> Heath
> 
>  
> 
> 

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

Reply via email to