Apache Struts 2 Documentation > Home > FAQs > Why won't the 'if' tag evaluate a one char string |

Apache Struts 2 Documentation
Why won't the 'if' tag evaluate a one char string
Edit Page Browse Space Add Page Add News
Added by digi9ten, last edited by Ted Husted on Jul 22, 2006 (view change) show comment hide comment
Comment:
Update parent page
View page history

If care is not taken with the quoting of literals, the expression language (OGNL) will misinterpret a char as a String.

Wrong

    <saf:if test="#myObj.myString == 'A'">
    Why doesn't this work when myString is equal to A?
    </saf:if>

The solution is simple: flip the double and single quotes.

Right

    <saf:if test='#myObj.myString == "A"'>
    This works!
    </saf:if>

Another solution is to escape the double quotes in the String.

Also Right

    saf:if test="#myObj.myString == \"A\"">
    This works too!
    </saf:if>