Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Question on EL  RSS feed

 
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
 
Sheriff
Posts: 9613
37
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"
 
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
 
Ranch Hand
Posts: 437
Java Oracle
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!