• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String concatenation in EL?

 
Ranch Hand
Posts: 109
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ranchers,

David Bridgewater writes in his book on page 492:

The following calculation won't work:
${"Not a number" + 3.0}
You will get a javax.servlet.jsp.el.ELException, complaining that "Not a number" cannot be converted to a java.lang.Double value. This example also goes to show that the addition operator in EL - unlike Java - is not overloaded to handle string concatenation. There is no operator overloading or string concatenation in EL.

But the Head First-book writes on page 428, Question 6:

${list['listIdx' + 1]} is incorrect because ('listIdx' + 1) becomes a String.

This sentence sounds like a string concatenation in EL, and I am not sure, which statement is true.

Is string concatenation allowed in EL or not?

Regards
Oliver
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think HFSJ is in error here, I remember trying it and the HFSJ's option actually gives an exception.

EL operator conversion has a lot of rules, here is a link that might help

http://commons.apache.org/el/apidocs/org/apache/commons/el/Coercions.html
[ August 22, 2007: Message edited by: Promod Mahajan ]
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Was this listed anywhere in the errata for the book?
 
Promod kumar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not listed in the errata. It may be because this option was not the right answer for this question. There is a correction for this question but it is on option F
 
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Oliver

Answer to your question in a single..

+ operator is not overloaded for String in EL



Now, I think you would be able to make out what is correct or what is wrong..

Regards,
Khushhal
 
Oliver Rensen
Ranch Hand
Posts: 109
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Promod and Khushhal, thanks a lot for your help.
 
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic