File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Badass: Making Users Awesome this week in the Game Development 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: 62269

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: 1261
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.

It is sorta covered in the JavaRanch Style Guide.
subject: EL Logical Operator type conversion