Reputation: 1057
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
.
Upvotes: 2
Views: 2823
Reputation: 50203
You do not even need to use <s:set>
.
Just fully exploit the Iterator
power:
<s:iterator var="itr" status="ctr" value="pages" >
<s:if test="%{itr[#ctr] < 5}">
Hello
</s:if><s:else>
Hi
</s:else>
</s:iterator>
Upvotes: 0
Reputation: 1
Should use
<s:set name="kk" value="0" />
instead of
<s:set var="kk" value="<s:property />" />
and you should not use <s:
tag in the attribute of struts tags
<s:set name="kk" value="0"/>
<s:iterator status="i" value="bloglist" >
<s:set name="kk" value="%{#kk+1}" />
<s:if test="%{(#kk<2)}">
Hello<br>
</s:if>
<s:else>
Hi<br>
</s:else>
</s:iterator>
Upvotes: 1
Reputation: 25613
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>
Upvotes: 3