Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL null handling

 
Ashu Jain
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please clarify rules related to null key/property in an EL expression.

I am refering HFSJ 1st Edition that says C is correct answer(Pg 432) but Erata of the book
"http://oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed"

says this: -

[432] Question 17, Option C;
option C is invalid and should not be checked.

Can someone please clarify rules related to null key/property in an EL expression.

My understanding is -

EL handles unknown or null values gracefully - no exception

Eg- ${foo} - If foo attribute does not exist in any scopes then print nothing
${foo.bar} - If foo Bean/Map exist but if bar does not exist as property than also print nothing

I can see few post that says that if bar property does not exist and EL will throw an exception.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${foo.bar} - If foo Bean/Map exist but if bar does not exist as property than also print nothing
I can see few post that says that if bar property does not exist and EL will throw an exception.
The latter is correct. If 'foo' is null, the expression evaluates to null (and if a String is required, nothing is printed). However, if 'foo' exists in a scope but has no 'bar' property, a runtime exception is thrown.

If this really bothers you, you should read the coercion rules in the JSP or EL specifications. Beware though, they are quite long and detailed!
 
Ashu Jain
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Charles. I will take your words. I have less time for exam day and can not afford to put reading long reading EL specs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic