File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Bean Property-Dot Operator.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Bean Property-Dot Operator.." Watch "Bean Property-Dot Operator.." New topic
Author

Bean Property-Dot Operator..

Sandya Bhaskara
Ranch Hand

Joined: Aug 20, 2004
Posts: 73
mock exam-chapter 8 question 17-
it says-

"if the . dot operator is used to access a bean property but the property does not exist,then a runtime exception is thrown."


but in chapter 9,page 447 (key points and gotchas- last point) it says EL expression by itself will NOT cause an exception if the property does not exist.so even though $(fooBean.notAProperty) won't cause an exception by itself(it just returns null) etc etc....

aren't these two contradictory???


Sandy<br />SCJP1.4 SCWCD1.4<br />SCBCD(preparing)
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
If I'm not mistaken, somewhere in the forum, this query had been addressed before (or at least mentioned).

Anyway, I think the statement meant that if your bean is missing & you tried to use the dot operator to access any of its property, its gonna result in an exception. Because the bean doesn't exist, so that's gonna throw you a NullPointerException.

But, if the bean exists, but does not have that property, no exception will be thrown.

HTH


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Gaurav Sahni
Ranch Hand

Joined: Sep 03, 2003
Posts: 56
Dear fellas,

Just could not digest what Lee is trying to say here.... the question still remains unanswered.

HFS pg. 424, question has one of the option which says clearly,

"If the .(dot) operator is used to access a bean property but the property does not exists, then a runtime exception is thrown."

and in the answers this is considered as "true" .


considering the forgiving nature of EL, if the bean is already present in the any scope, this should be false....


To know recursion, you must first know recursion...
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
This is an error in the book!!


It should NOT be marked as *correct*, so, give yourself a point if you left option "C" unchecked. You're absolutely right--"C" should not be marked as correct.

Sorry...
-Kathy
Gaurav Sahni
Ranch Hand

Joined: Sep 03, 2003
Posts: 56
Thanx a lot Kathy.
U always save the day for us.


Gaurav.
Gaurav Sahni
Ranch Hand

Joined: Sep 03, 2003
Posts: 56
I am confused today again.

I tried to test this using tomcat5.0.
If a bean 'bar' exists, whic does NOT have a property 'foo' ,
then the following statement
${bar.foo}
give the following error:


javax.servlet.ServletException: Unable to find a value for "saa" in object of class "practise.wcd.person" using operator "." ......




This means that the above assumption
"If the .(dot) operator is used to access a bean property but the property does not exists, then a runtime exception is thrown."

is indeed correct. :roll:

Things are still not clear...

Gaurav.
Gaurav Sahni
Ranch Hand

Joined: Sep 03, 2003
Posts: 56
I would greatly appreciate if anybody can clear this mud.
:roll: :roll: :roll:

Gaurav.
Jonatan Samoocha
Greenhorn

Joined: Nov 20, 2001
Posts: 16
Hi all,

when skimming through HFS I ran into the same confusion about the "." operator. The mock exam answer on page 432 does clearly contradict with the last "Gotcha" on page 447 (see initial post in this thread).

I'm affraid Kathy's reply in this thread was incorrect, which increased the confusion. After running a test similar to the one used by Gaurav, it seems like trying to access a non-existing bean property does cause an exception to be thrown. This behavior is confirmed by the JSP2.0 spec (see JSP2.3.4, page 1-68 /1-69), which states that an error is thrown if EXPR2 in EXPR1.EXPR2 is not "...a readable property of EXPR1, as per the JavaBeans specification".

Based on the test and the JSP spec, I think we can conclude that (i) the mock exam answer on page 432 is correct, and (ii) the last "Gotcha" remark on page 447 is incorrect.

Please cross-check these conclusions since I don't consider myself a JSP guru (in fact, I'm just beginning to prepare for the exam).
Giju George
Ranch Hand

Joined: Jun 08, 2004
Posts: 333
Even I got a javax.servlet.ServletException


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCEA
Krzysiek Hycnar
Ranch Hand

Joined: Jan 02, 2004
Posts: 74
Hi all,

Come on you guys, this is simple!!

For the the EL like <c ut value="${bean.propertyThatDoesNotExist}" />

The rule is: if the bean EXISTS, but the property you're trying to access DOES NOT EXIST, you get an exception - in Tomcat it is org.apache.jasper.JasperException with the description kind of - Unable to find a value for "propertyThatDoesNotExist" in object of class "test.scwcd.bean.MyBean" using operator "." (null) (The same will happen if the property exists, but there's no getter.)

On the other hand if the bean DOES NOT EXIST you will NOT get an exception - the code will not print anything.

Cheers
Chris
Sameer Raza Ali
Greenhorn

Joined: Oct 15, 2009
Posts: 20
There needs to be a correction in the book

In q 17 The option C is unchecked
If the . (dot) operator is used to access a bean property but the
property doesn’t exist, then a runtime exception is thrown.

should be checked It is true.

This is also tested in question
Q 10- Which show valid usage of EL implicit variables?

option C. ${pageContext.foo}

Option C is incorrect because pageContext is NOT a Map and it doesn’t have a “foo” property.


SCJP 1.4 , SCWCD 5.0
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Sameer, that thread is 5 years old. The error has already been added to the errata since then (search for "Page 437" on that page). In future create a new topic for your question instead of replying to a 5 year old thred...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sameer Raza Ali
Greenhorn

Joined: Oct 15, 2009
Posts: 20
sorry didn't see the date on the last message, but i replied here because this thread came up in google search the next person to visit this thread will have no confusion regarding this...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bean Property-Dot Operator..
 
Similar Threads
Bean Property-Dot Operator..
EL access operator
dot operator
Bean property
True/False?