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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
wiki
  • 3,379
  • 3
  • 20
  • 13

3 Answers3

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>
Romain Linsolas
  • 79,475
  • 49
  • 202
  • 273
22

Both works. Instead of == you can write eq

kiritsuku
  • 52,967
  • 18
  • 114
  • 136
6

You can check this way too

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