PDA

View Full Version : JSTL and string concatenation possible?


kantorn
Aug 19th, 2004, 07:58 AM
I have ${stub} = 2@3# and ${levels} = [1, 2, 3, 4]

I would like to do something like

<c:forEach var="level" items="${levels}">
<c:out value="${stub}${level}"/>
</c:forEach>


resulting in

2@3#1
2@3#2
2@3#3
2@3#4


I've tried every(?) possible combination. Is String concat without any blankspace possible in JSTL?

irbouho
Aug 19th, 2004, 09:19 AM
did you try

<c:forEach var="level" items="${levels}">
<c:out value="${stub}"/><c:out value="${level}"/>
</c:forEach>

kantorn
Aug 19th, 2004, 09:39 AM
Problem is I have to assign it to a new variable:


<c:set var="stubplus" value="<c:out value="${stub}"/><c:out value="${level}"/>" />


Chokes on "unterminated tag" unforunately....

irbouho
Aug 19th, 2004, 10:02 AM
Then try this

<c:forEach var="level" items="${levels}">
<c:set var="stubplus" value="${stub}${level}" />
<c:out value="${stubplus}"/>
</c:forEach>

irbouho
Aug 19th, 2004, 10:36 AM
Mark Kolb wrote a good article about JSTL (http://www-106.ibm.com/developerworks/java/library/j-jstl0211.html) on developerWorks.

kantorn
Aug 19th, 2004, 03:50 PM
Thanks! Appreciate your answers.