• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No.10 note in Scwcd Hints is wrong?

 
Chrix Wu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read this on Scwcd Hints

10) ${"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's no operator overloading or string concatenation in EL.


but i also read this on head first book at page 428 mock question 6

${list["listIdx" + 1]} , ("listIdx" + 1) becomes a String ~


I am confused now...

anyone got any ideas?

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${list["listIdx" + 1]} , ("listIdx" + 1) becomes a String

I don't think it will. "listIdx" + 1 should be evaluated as an Integer, thus an error occurs.
 
Niteen Patil
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider,
${list['listIdx'+1]}

here, 'listIdx' is a string in ['listIdx'+1]. EL will try to coerce 'listIdx' to a long which is not possible.

The character inside the quotes should be a digit [0-9] .
i.e,
${list['1'+1]} would be converted to ${list[2]}

Thanks,
Nitin.
 
Chrix Wu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what the HFSJ book said is incorrect?
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many mistakes. Have a look on errata.
 
Chrix Wu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic