JSTL how to combine values?
I got the following code:
<c:forEach var="i" begin="1" end="${finalDisccount}">
<p><c:out value="${tracksCD}" /> Tracks für CD${i} hochladen</p>
<p><input id="filename_${i}" type="file" name="filename_${i}" size="50" multiple="multiple" required="required"/></p>
</c:forEach>
The value of "tracksCD" must be combined with the variable i, so something like this is created by the loop:
<p><c:out value="${tracksCD1}" /> Tracks für CD${i} hochladen</p>
<p><c:out value="${tracksCD2}" /> Tracks für CD${i} hochladen</p>
Etc. Is there a way to combine $ {tracksCD} and $ {i} to get $ {tracksCD1}, etc. Dynamically?
Thanks in advance.
If you know the amount of data, you can simply access it in the scope map ${requestScope}, ${sessionScope}or ${applicationScope}. For instance. when it is in the request area:
<c:forEach var="i" begin="1" end="${finalDisccount}">
<c:set var="tracksCDKey" value="${tracksCD}${i}" />
<p><c:out value="${requestScope[tracksCDKey]}" /> Tracks für CD${i} hochladen</p>
<p><input id="filename_${i}" type="file" name="filename_${i}" size="50" multiple="multiple" required="required"/></p>
</c:forEach>
However, you have a rather nasty design error. Rather, collect them in an array or list like ${tracksCDs}so that you can do the following:
<c:forEach var="i" begin="1" end="${finalDisccount}">
<p><c:out value="${tracksCDs[i - 1]}" /> Tracks für CD${i} hochladen</p>
<p><input id="filename_${i}" type="file" name="filename_${i}" size="50" multiple="multiple" required="required"/></p>
</c:forEach>
Or maybe if it ${finalDisccount}is the same size as the array / list:
<c:forEach items="${tracksCDs}" var="${tracksCD}" varStatus="loop">
<p><c:out value="${tracksCD}" /> Tracks für CD${loop.count} hochladen</p>
<p><input id="filename_${loop.count}" type="file" name="filename_${loop.count}" size="50" multiple="multiple" required="required"/></p>
</c:forEach>