Search code examples
javajspstruts2jsp-tagsognl

Struts if tag with iterator tag is not working


I am trying to use Struts if tag with iterator but it is not working.

Here is the code for this:

<s:iterator status="i" value="pages" >
   <s:set var="kk" value="<s:property />" />     
                
   <s:if test="%{(#kk<5)}">
      Hello
   </s:if><s:else>
      Hi
   </s:else>                        
</s:iterator>

The pages list is a list of integers.

The above code should print Hello if pages value is less than 5 but print it for all values of pages.


Solution

  • There's so many options with OGNL, jstl and so on that it can become a nightmare to retrieve a value. Try with this one, I think in the following case the %{} is not mandatory

    <s:iterator id="page" value="pages">
       <s:if test="#page < 5">Hello</s:if> <!-- or <s:if test="%{#page < 5}"> -->
       <s:else>Hi</s:else>
    </s:iterator>