Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check a boolean condition in EL?

Tags:

java

jsp

el

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> 
like image 824
wiki Avatar asked Oct 12 '10 14:10

wiki


People also ask

How do you know if a condition is boolean?

parseBoolean(String s) − This method accepts a String variable and returns boolean. If the given string value is "true" (irrespective of its case) this method returns true else, if it is null or, false or, any other value it returns false.

How do you write a boolean condition in an if statement?

An if statement checks a boolean value and only executes a block of code if that value is true . To write an if statement, write the keyword if , then inside parentheses () insert a boolean value, and then in curly brackets {} write the code that should only execute when that value is true .

How do you show boolean?

To display Boolean type, firstly take two variables and declare them as boolean. val1 = true; Now, use if statement to check and display the Boolean true value. if(val1) System.

What is boolean condition in Java?

A Boolean expression is a Java expression that returns a Boolean value: true or false .


1 Answers

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> 
like image 136
Romain Linsolas Avatar answered Oct 06 '22 01:10

Romain Linsolas