<s:if> test expression evaluation for boolean value doesn't work as expected

Akash Jain picture Akash Jain · Apr 15, 2014 · Viewed 37.5k times · Source

I want to check value of variable bool_val using Struts2 tag <s:if> but it's not working.

<%@ taglib prefix="s" uri="/struts-tags" %>

<%boolean bool_val=true;%>
real value : <%=bool_val%><br/>
expression evaluated value : 
<s:if test="%{bool_val==true}">
    TRUE
</s:if><s:else>
    FLASE
</s:else>

I also tried following test expressions too, but still not working.

<!-- 
bool_val
bool_val==true
%{bool_val}
%{bool_val==true}
%{bool_val=="true"}
 -->

Answer

Visruth picture Visruth · Apr 15, 2014

Use struts tag to create a variable like this

<s:set var="bool_val" value="true" />
expression evaluated value : 
<s:if test="%{#bool_val == true}">
    TRUE
</s:if><s:else>
    FALSE
</s:else>

Here is a sample tutorial.