wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Question on EL 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 "Question on EL" Watch "Question on EL" New topic
Author

Question on EL

Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
In HFSJ chapter test question 6



My question is why not E....what is the difference between D and E?

Thanks
Veena


SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Do you remember the statement from the HFSJ book, whatever inside the [] which is not in quotes will be evaluated. Thus in ${list[listIdx+1]} listIdx will evaluate to 1 but in ${list['listIdx'+1]}, it will try to concatenate 1 to the String listIdx and since there's no string concatenation in EL, you'll get an error...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
I understood if it is not within quotes it will be evaluated.But I didn't understand why option E is incorrect.The explanation given in the book is "Option E is incorrect because EL tries to coerce 'listIdx' to a Long which is invalid "....why it tries to coerce it to Long?

I get following exception for Option E

javax.servlet.ServletException: An exception occured trying to convert String "listIdx" to type "java.lang.Long"
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 452

Veena Pointi wrote:I understood if it is not within quotes it will be evaluated.But I didn't understand why option E is incorrect.The explanation given in the book is "Option E is incorrect because EL tries to coerce 'listIdx' to a Long which is invalid "....why it tries to coerce it to Long?

I get following exception for Option E

javax.servlet.ServletException: An exception occured trying to convert String "listIdx" to type "java.lang.Long"


in EL 'xyz' has the same meaning as that of "xyz" . hence here it will not look for any attribute named xyz in any scope.i.e. you are trying to add a string and a number here.
now EL will try to convert the string into a numeric value so that it can be added to the number provided which is not possible here.

avi sinha


SCJP 5.0 SCWCD 5.0
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi, Veena.
....why it tries to coerce it to Long?

I think, the designers used 'Long' inorder to support huge values. See coersion rules.
Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
Thanks alot Avi,Chinmay for replieng.It cleared my doubts.

Thanks again
Veena
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Question on EL
 
Similar Threads
Pg. 420 - Q.6 of HF book
Head First Servlets and JSP Chapter 8 Mock exam
Doubt in HFSJ page-420
Doubt in mock question on page no. 433 of Head First Servlets & JSP 2nd edition Chapter 8
Please tell me the correct answer