How to check a boolean condition in EL?
Asked Answered
R

3

96

Is this correct?

<c:if test="${theBooleanVariable == false}">It's false!</c:if>

Or could I do this?

<c:if test="${!theBooleanVariable}">It's false!</c:if>
Roodepoortmaraisburg answered 12/10, 2010 at 14:27 Comment(0)
L
131

You can have a look at the EL (expression language) description here.

Both your code are correct, but I prefer the second one, as comparing a boolean to true or false is redundant.

For better readibility, you can also use the not operator:

<c:if test="${not theBooleanVariable}">It's false!</c:if>
Laurice answered 12/10, 2010 at 14:36 Comment(0)
I
22

Both works. Instead of == you can write eq

Ideatum answered 12/10, 2010 at 14:35 Comment(0)
M
6

You can check this way too

<c:if test="${theBooleanVariable ne true}">It's false!</c:if>
Mummer answered 7/7, 2015 at 19:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.