Struts if tag doesn't work
I'm trying to use the Struts tag if
with an iterator, but it doesn't work. Here is the code for that
<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>
A list pages
is a list of integers. The above code should print Hello
if the value is pages
less than 5, but print it for all values pages
.
source to share
There are so many options out there with OGNL, jstl, etc. that it can be a nightmare to get the value. Try with this, I think the following case %{}
is optional
<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>
source to share
Must use
<s:set name="kk" value="0" />
instead
<s:set var="kk" value="<s:property />" />
and you shouldn't use the tag <s:
in the struts tag attribute
<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>
source to share