The Coder
The Coder

Reputation: 2632

Comparing two List values in JSTL tag

I'm comparing two different values each from different list using JSTL tag, but I keep getting the error. I tried to change the brackets associated with it, but none worked. I searched for comparing two list values in JSTL, but none helps me.

<c:forEach items="${commentsList}" var="commentsList">
    <c:choose>
        <c:when test="${ ${commentsList.user.id} == '${blog.user.id}' }">
            <li>
                <div class="timeline-panel" style="float:right">
                    <div class="timeline-heading" align="left">
                        <b>${commentsList.user.firstName}&nbsp;${commentsList.user.lastName}</b>
                    </div><hr>
                    <div class="timeline-body" style="float: right;">
                        <p>${commentsList.comment}</p>
                    </div>
                </div>
           </li>
       </c:when>                            
       <c:otherwise>
           <li class="timeline-inverted">
                <div class="timeline-panel">                                         
                    <b>${commentsList.user.firstName}&nbsp;${commentsList.user.lastName}</b><hr>
                    <div class="timeline-body">
                        <p>${commentsList.comment}</p>                                                  
                    </div>
                </div>
            </li>
        </c:otherwise>                              
    </c:choose>
</c:forEach>

Error is

"${ ${commentsList.user.id} == '${blog.user.id}' }" contains invalid expression(s): javax.el.ELException: Error Parsing: ${ ${commentsList.user.id} == '${blog.user.id}' }

I've not compared two list values before, btw I can compare two list values in jstl right?

Upvotes: 1

Views: 2243

Answers (2)

Master Slave
Master Slave

Reputation: 28569

You should change to

<c:when test="${commentsList.user.id eq blog.user.id}">

Upvotes: 1

Super Hornet
Super Hornet

Reputation: 2907

there is an extra $. try this:

<c:when test="${ commentsList.user.id eq blog.user.id}">

Upvotes: 2

Related Questions