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: null-friendly vs exceptions

 
Joe Allen
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HFSJ book EL chapter, it says EL is null-friendly and handles null values gracefully.

For example, there is an attribute named "bar", which does not have a property or key named "foo".
${bar[foo]} is null, since foo is not a property or a key of bar, but EL handles it gracefully. It just shows nothing printed out.

My understanding is, behind the scene, there is an exception thrown, am I right?
By the way, I don't have my environments set up yet. I usully do it after I go throught the book, then I'd try on those cases that I am not sure of. I just need a quick confirmation from those knowledgables whether I am right or not. Or I'll wait to find out myself after I go through the book.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65338
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Allen wrote:My understanding is, behind the scene, there is an exception thrown, am I right?

Unlikely. It's much more likely that the EL interpreter will do null checks.
 
Joe Allen
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear, thanks for answering my question again.

The reason I thought there was an exception thrown behind the scene is because in doing item 17 (pg 437) of HFSJ chapter 8 mock exam, I didn't get one of the two correct answers right. I thought null-friendly means no exceptions.

17) Which about EL access operators are true?
C. If the .(dot) operator is used to access a bean property but the property doesn't exist, then a runtime exception is thrown. (one of the two correct answers)

But again, it could be an errdata too. That is why I posted the question.
 
Joe Allen
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just came upon the answer, as I was reading HFSJ. It says, in p457(about <c:set target= property= value= >), "If the "target" expression is a bean, but the bean does not have a property that matches "property", the Container throws an exceiption. Remember that the EL expression ${bean.notAProperty} will also throw an exception.".

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic