• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

EL null handling

 
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.
 
Author
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.
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic