How to check a boolean condition in EL?

JavaJspEl

Java Problem Overview


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>

Java Solutions


Solution 1 - Java

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>

Solution 2 - Java

Both works. Instead of == you can write eq

Solution 3 - Java

You can check this way too

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionwikiView Question on Stackoverflow
Solution 1 - JavaRomain LinsolasView Answer on Stackoverflow
Solution 2 - JavakiritsukuView Answer on Stackoverflow
Solution 3 - JavaShamsView Answer on Stackoverflow