${test}
<c:forEach items=" ${test}" var="sharedType">
${sharedType}<br/>
<c:if test="${sharedType == 2}" >
<span class="tweet-button"></span>
</c:if>
<c:if test="${sharedType == 1}" >
TEST
<a href="#" class="fbshare-button">Share</a>
</c:if>
</c:forEach>
The integer list is 1,2,3.
On my page, it show [1,2,3] for ${test}, and “[1” “2” “3” for ${sharedType} in 3 iterations. Looks like JSTL think it is a String separated by comma rather than a list.
The code to generate the list in java is:
List<Integer> test= new ArrayList<Integer>();
test.add(1);
test.add(2);
test.add(3);
I have been struggling with this for a while, can anyone help me with this? Thanks.
Just checked it in my app and so put it as an answer: try removing space from
items=" ${test}". Otherwise, you’re executing equivalent of this java expression" " + testList. Obviously, the result is not a list.and “[1” “2” “3” for ${sharedType} in 3 iterations
Most likely there was only one iteration and you’re seeing the result of
test.toString()call.