How to check a boolean condition in EL?

wiki picture wiki · Oct 12, 2010 · Viewed 177.3k times · Source

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>

Answer

Romain Linsolas picture Romain Linsolas · Oct 12, 2010

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>