質問

I am trying to associating this two arraylist and print..

            <c:when   test="${postitem.posttype.equals('text')}">
                <h5>id="${postitem.postid}"</h5> 
                <pre>  ${postitem.postdata}  </pre>
                <span>datetime="${postitem.posttime}</span>
                <c:forEach items="${postitem.comment}" var="comment">
                    <span>comment="${comment}" </span>
                </c:forEach>
                <c:forEach items="${postitem.commenttime}" var="comment_time">
                    <span>comment_time="${comment_time}"  </span>
                </c:forEach>
            </c:when>

i want to print "comment" with "comment time" that are the values of two different arraylists but this code is printing whole first arraylist and then second one.

any hint???!

役に立ちましたか?

解決

You have to use varStatus attribute to get the current index, and print elements from both arraylists at that index (this is of course assuming that both arraylists contains same number of elements):

<c:forEach items="${postitem.comment}" var="comment" varStatus="status">
    <span>comment="${comment}" </span>
    <span>comment_time="${postitem.commenttime[status.index]}"  </span>
</c:forEach>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top