• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL Logical Operator type conversion

 
Devang Ganatra
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't really converted. Any value that doesn't have a conversion to Boolean evaluates as false.
 
Stefan Evans
Bartender
Posts: 1743
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Cheers,
evnafets
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic