| 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
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9191
|
|
|
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
|
 |
 |
|
|
subject: Question on EL
|
|
|