• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

EL null handling

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic