Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes 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
Pie
Posts: 65335
97
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic