It's not a secret anymore!
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes how EL handles the null values Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "how EL handles the null values" Watch "how EL handles the null values" New topic
Author

how EL handles the null values

sriram kalakoti
Greenhorn

Joined: Jan 07, 2006
Posts: 17
hi
i have my exam, next monday and iam still confused with how the EL handles the null values

can anybody please clarify abt how El handles unknown values my confusion is when exception is thrown and when nothing is printed???


Thanks in advance
Sriram
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

I can tell you two case where the exception will thrown.
1. When you are trying to access non-existent bean property.
2. When the attributes to list/arrays can not coerec to int.

hope it help

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
MInu
Ranch Hand

Joined: Oct 09, 2003
Posts: 517
Try these cases,you will get a blank screen

1.Try to access an array index which is greater than the actual size

eg:${list["5"]}

2.Try to access a non-existent map key.

eg: ${m.C} //C is not a valid map key.

correct me if its wrong

Thanks


God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
sriram kalakoti
Greenhorn

Joined: Jan 07, 2006
Posts: 17
Thanks for the replies guys

so if foo is an attribute but foo doesnot have a property 'name'
then ${foo.name} or ${foo[name]} will throw an exception right???

but in HFSJ pg 395 it says it will NOT throw an exception but just prints nothing.

need u people help again
Thanks
Sriram
Ernesto Leyva
Ranch Hand

Joined: Feb 23, 2006
Posts: 62
I think EL trys to print as much as possible and is forgiving about null values so if you have a null object will print nothing a number not initialied will be zero and a boolean will be false.
K Bala
Greenhorn

Joined: Jul 14, 2005
Posts: 28
EL handles null values in the following ways:

The logical operators treat a null value as false.

The arithmetic operators treat a null value as zero.

If you do division by zero, it returns infinity and does not throw any exception.

Hope this helps.


Quitters never win; Winners NEVER QUIT!!!
Frederic Esnault
Ranch Hand

Joined: Feb 13, 2006
Posts: 284
I agree with K Bala's answer. Null values are treated in a very elegant way, without throwing any excpetion. The philosophy is that it's always better to show the user a blank where an information is expected than an ugly excpetion page.

Just a little point to add :

There is actually one case where EL throws an exception. When an EL function is defined, linked to a java class with a public static method to handle it. If this method throws an exception, the exception is wrapped into an ELException and thrown to the JSP error handling mechanism.


SCJP 5 - SCWCD 1.4 - SCBCD 1.3 - Certification study documents/resources: http://esnault.frederic.free.fr/certification
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how EL handles the null values
 
Similar Threads
EL access operator
EL doubt
EL null handling
Jsps and Servlets
JSTL Syntax