Chris V.
Chris V.

Reputation: 1143

Make a list item of specific index bold with JSTL

I have an ordered list of names, and I need to make the third item on the list bold. Only the third item should be bold. After that it should return to regular font. Here's what I have as of now:

<ol>
    <c:forEach items="${names}" var="entry" varStatus="status">
        <li>
            ${entry}
            <c:if test="${entry eq 'Jeff'}"> is a grader.</c:if>
            <c:if test="${entry eq 'jeff'}"> is a grader.</c:if>
        </li>
    </c:forEach>
</ol>

Would I still be using <b> tags, or is there another way to bold certain text (using JSTL)?

Upvotes: 1

Views: 1679

Answers (1)

BalusC
BalusC

Reputation: 1108712

Make use of the varStatus="status" you got there. It refers to a local LoopTagStatus instance which offers you among others the (self-explaining) getIndex() method.

<c:if test="${status.index == 2}"><b>This is the 3rd item.</b></c:if>

(yes, also here, array indexes start at 0)

Upvotes: 3

Related Questions