Question

My if statement is always evaluating to false and not entering the <span> block. Because of which, I'm not able to get the value of "index" in the if condition, I've tried every thing appending index with # and %. Can anybody suggest the solution?

<c:forEach var="index" begin="1" end="<%=a%>" step="1">
    <s:if test="index == 1">
        <span class="currentpage"><b>${page_id}</b></span>
    </s:if>
    <s:else>
        <a href="searchAction.html?page_id=${index}&searchString=${searchString}" class="paginglinks">${index}</a>
    </s:else>
</c:forEach>
Was it helpful?

Solution

got it actully it is some conflict in the tags

it should be like

<c:forEach var="index" begin="1" end="<%=a%>" step="1" varStatus="status">
                            <c:choose>
                            <c:when test="${page_id==index}">                       
                                <span class="currentpage"><b>${page_id}</b></span>
                            </c:when>
                            <c:otherwise>
                            <a href="searchAction.html?page_id=${index}&searchString=${searchString}" class="paginglinks">${index}</a>
                            </c:otherwise>
                            </c:choose>
                            </c:forEach>

OTHER TIPS

The conflict is that at the first post you are mixing

  • JSTL tags (the c:forEach)
  • Struts tags (the s:if)

Your proposed solution works because you now have

  • JSTL tags (the c:forEach)
  • JSTL tags again (the c:when)

Another good solution would be

  • Struts tags (the s:iterator)
  • Struts tags again (the s:if)

Generally speaking, using tags from multiple technologies is expected to be problematic.

use

 test="${index == 1}"

or try using the varStatus attribute so...

<c:forEach var="index" varStatus="status" begin="1" end="<%=a%>" step="1">

 <s:if test="${status.count == 1}">
  <span class="currentpage"><b>${page_id}</b></span>
 </s:if>
 <s:else>
  <a href="searchAction.html?page_id=${index}&searchString=${searchString}" class="paginglinks">${index}</a>
 </s:else>
</c:forEach>

The test value isn't evaluatable, it's just a string to the page.

Edit, you have you use strut's syntax.

Add "%{}", like so:

<s:if test="%{index == 1}">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top