Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EL operator empty

 
Luis Centeno
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote below jsp code in order to test EL operator empty



and it returns

empty nonExistingAttr: true
empty string1: true
empty "": true
empty null: true

I am not sure how come ${empty string1} and ${empty ""} evaluate to true since string1 attribute exists and "" is not null.

Is empty operator intended to test empty strings as well as null values?
 
Luis Centeno
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just found myself the answer in JSP spec (2.3.7)


Empty Operator - empty A
• If A is null, return true,
• Otherwise, if A is the empty string, then return true.
• Otherwise, if A is an empty array, then return true.
• Otherwise, if A is an empty Map, return true,
• Otherwise, if A is an empty Collection, return true,
• Otherwise return false.


Thanks and I hope this topic helps others
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65653
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Spec is the first place to consult.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!