• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on EL

 
Veena Pointi
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HFSJ chapter test question 6



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

Thanks
Veena
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Veena Pointi
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot Avi,Chinmay for replieng.It cleared my doubts.

Thanks again
Veena
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic