Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

c:set tag with and without body

 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming myMap is a java.util.Map with String as key and Object as value. Are they 100% equivalent?

versus


I tested it with tomcat5.0 and it seems that the EL inside a tag body is converted to String first before assigned to the map. Is there any way to preserve the original type of myObject while using the version with a body?
[ September 05, 2005: Message edited by: Bear Bibeault ]
 
Marshal
Posts: 67414
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. When an EL expression is used in template text, its behavior is to be evaluated, that value converted to string, and then emitted to whatever writer is in scope at the moment -- in this case, the writer for the tag body. By the time the tag gets the body context, the value has been been long ago converted.

Also note that the whitespace within the tag body -- line terminators and indentation -- are included as part of the tag body in your second example.
[ September 05, 2005: Message edited by: Bear Bibeault ]
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic