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 Doubt

 
sunitha nerevetla
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the following right?

${a.b} - throws exception if a exists and b doesn't exist
${a[b]} - Displays nothing if a exists and b doesn't exist
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

if any one of the following evaluates null, the result will be null
not an exception.
for eg ${a.b} -> either a evaluates null or b evaluates null , the complete expression results null not an exception

Bye for now
sat
(I am also a beginner in JSTL & EL)
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on if what you have there is a bean or a list (et al).

The spec goes into it quite extensively, but is a bit hard to grasp.

Mostly, if there's a problem, you get back a blank, and the page runs okay, but there are a few error conditions. Here's the way I think it works according to the spec (implementations might be more friendly, I think):

To evaluate "${a[b]}":

If "a" is a Map:
(no errors)

If "a" is a List or array:
error if "b" can't be turned into an int.
error if getting the value throws
something OTHER than an 'out of bounds'.

If "a" is a JavaBeans object:
error if "a.getB" doesn't exist.
error if the getter throws an exception.

--Dale--
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone confirm that what I've got in the previous post is right?

--Dale--
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although I allocated this time to study for the test, I find myself doing anything but study. So here's what I've done since that previous post:

EL square brackets are quite friendly bulls;
there's no puke on your users when they return nulls.

If the thing on the left is an array or a list,
the non-coercable index error can not be missed.

If a bean is the thing on the left that you had,
errors will flow if your getter is bad.

Arrays and lists can stand only so much;
out of bounds is okay but exceptions go "crunch".

A map on the left is the safest to use,
just pass the test soon, and then hit the booze.

--Dale--
[ February 06, 2005: Message edited by: Dale Seng ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic