Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String concatenation in EL?

 
Oliver Rensen
Ranch Hand
Posts: 109
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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
 
Promod kumar
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • 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 ]
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
khushhal yadav
Ranch Hand
Posts: 242
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Promod and Khushhal, thanks a lot for your help.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic