<c:forEach items="${myParams.items}" var="currentItem" varStatus="stat"> <c:set var="myVar" value="<c:out var="myVar" />" /> </c:forEach>
I want to concatenate the values of currentItem.myVar and output it at the end of the loop, problem is I can't figure out how to do this...
(Preferably not using Java)
Python concatenate strings in for loop To concatenate strings we will use for loop, and the “+ ” operator is the most common way to concatenate strings in python.
JSTL - fn:join() Function The fn:join() function concatenates all the elements of an array into a string with a specified separator.
You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.
Perhaps this will work?
<c:forEach items="${myParams.items}" var="currentItem" varStatus="stat"> <c:set var="myVar" value="${stat.first ? '' : myVar} ${currentItem}" /> </c:forEach>
You're using JSTL 2.0 right? You don't need to put <c:out/>
around all variables. Have you tried something like this?
<c:forEach items="${myParams.items}" var="currentItem" varStatus="stat"> <c:set var="myVar" value="${myVar}${currentItem}" /> </c:forEach>
Edit: Beaten by the above
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With