views:

466

answers:

4

Hello. 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>
A: 

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}">
sblundy
Nope if i use ${} in that test , getting that funny error "attribute test does not accept any expressions"
Vinayak.B
sorry what u suggested will become a syntax error
Vinayak.B
sorry index cant b resolved
Vinayak.B
A: 

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>
adam
Nope if i use ${} in that test , getting that funny error "attribute test does not accept any expressions"
Vinayak.B
A: 

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>
Vinayak.B
+1  A: 

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.

kazanaki