Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   JSTL: How do I set an array variable? (http://www.velocityreviews.com/forums/t124517-jstl-how-do-i-set-an-array-variable.html)

Derek Mahar 07-17-2003 03:48 PM

JSTL: How do I set an array variable?
 
How do I use the JSTL <c:set> to set an array variable that I may
subsequently iterate over with <c:forEach>?

Thanks,

Derek

Scott Yanoff 07-17-2003 09:13 PM

Re: JSTL: How do I set an array variable?
 
Derek Mahar wrote:
> How do I use the JSTL <c:set> to set an array variable that I may
> subsequently iterate over with <c:forEach>?


A weak solution is to set a delimited string to simulate and array:
<c:set var="brewers">Richie Sexson, Eric Young, Ben Sheets, Geoff
Jenkins, Brady Clark, Scott Podsednik, Keith Ginter</c:set>

Then, use forTokens to iterate through it:
<c:forTokens items="${brewers}" delims="," var="brewer">
<li><c:out value="${brewer}">
</c:forTokens>

Good luck,
--
-Scott
yanoff@STOP-SPAMMINGyahoo.com | http://www.yanoff.org | AOL IM: SAY KJY


DoggieDaddy 06-07-2011 06:39 PM

JSTL Setting Arrays
 
THIS:
<%
String[] yankees = {"Jeter", "Posada", "Rodriguez", "Kanoe", "Rivera", "Swisher"};
pageContext.setAttribute("yankees",yankees, PageContext.REQUEST_SCOPE);
%>

IS THE SAME AS THIS:
<c:set var="yankees" scope='request'>"Jeter", "Posada", "Rodriguez", "Kanoe", "Rivera", "Swisher"</c:set>

AND BOTH CAN BE PRINTED LIKE THIS:
<c:forEach var="yankee" items="${yankees}">
Name: <c:out value="${yankee}" /><br />
</c:forEach>


All times are GMT. The time now is 05:35 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.