Mihir Chauhan
Mihir Chauhan

Reputation: 141

associating two ArrayList in JSP

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???!

Upvotes: 1

Views: 121

Answers (1)

Rohit Jain
Rohit Jain

Reputation: 213311

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>

Upvotes: 1

Related Questions