This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes JSP and the fly likes EL Logical Operator type conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "EL Logical Operator type conversion" Watch "EL Logical Operator type conversion" New topic

EL Logical Operator type conversion

Devang Ganatra

Joined: Feb 19, 2008
Posts: 5
Hello .
i am using following code in my JSP

${not "Hello"}.

In output it is displayed as true. So i want to know that what is the formula of type conversion for String to Boolean . Because not operator can only be applied to boolean values. so how this String value converted to Boolean value?

Please explain me
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63334

It isn't really converted. Any value that doesn't have a conversion to Boolean evaluates as false.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans

Joined: Jul 06, 2005
Posts: 1518
The JSTL rules to coerce something to a boolean value
Coerce A to Boolean
- If A is null or "", return false
- Otherwise, if A is Boolean, return A
- Otherwise, if A is String, and Boolean.valueOf(A) throws exception, error.
- Otherwise. if A is String return Boolean.valueOf(A)
- Otherwise, error

Boolean.valueOf("Hello") evaluates as false.

I agree. Here's the link:
subject: EL Logical Operator type conversion
It's not a secret anymore!