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

Attribute type conversion for custom tags.

 
Rohit Kelkar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the type conversion for the custom tag attributes happen automatically? Or is the programmer supposed to handle the type conversion class setXXX() method?
 
g madhava
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you specify rtexprvalue to be true,you could specify the type in the attribute,so that you could directly get on the corresponding type of setXXX(Type type)
 
Rohit Kelkar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fine,
But in case rtexprvalue is not set to true, the programmer is supposed to handle the type conversion from String to ......Right?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read section 2.13 of the spec. The JSP container will do no automatic conversions on runtime expressions. In other words,translates down towhatever the expression is. The normal Java type conversion and method overloading rules apply.
The specification spells out how translation-time attributes are converted. Primitives (e.g. int) and primitive wrapper objects (e.g. Integer) can be automatically constructed from Strings. An Object argument simply gets the String. And remember that tags are full-blown JavaBeans, so you can get all kinds of custom conversions by giving the bean a PropertyEditor with a setAsText() implementation.
- Peter
 
Rohit Kelkar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks peter,
I tried out the examples myself and it makes much more sense on how the casting works.
Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic