Jill Foley wrote:
>
> I'm reading about tag libs and I have a question about
> attributes.
>
> I read "The attribute value is supplied to the method as a
> String". But then I saw an example of a tag handler for the tag
>
> <tlt:twa attr1="value1">
>
> that had:
>
> private AttributeClass attr1;
> setAttr1(AttributeClass ac) {...}
>
> So my question is: can an attribute be any java object? Can I do
> this?:
>
> <mylib:presonHeader param="<%= personBean.getPerson() %>" />
>
> and have a setParam(Person person) in my tag handler?
None of the answers I've seen so far is 100% right, so let me try to
clarify what the spec says you can and can not do.
If you use a literal string as the attribute value, such as
<tlt:twa attr1="value1" />
the JSP container looks at the type of the corresponding property in the
tag handler class to see if the value needs to be converted. If the
property is of type boolean, Boolean, byte, Byte, char, Character, double,
Double, int, Integer, float, Float, long or Long, it will try to convert
the string value to the correct type for the property. If the property
is a String, the value is of course used as is. If it's something else,
you get a translation-time error.
If you need to use an attribute that is not one of the types listed above,
you need to use a request-time attribute value, such as
<tlt:twa attr1="<%= personBean.getPerson() %>" />
When you use a request-time attribute value, the JSP container does not
attempt to do any type conversion. In other words, the type of the
expression must match the type of the corresponding tag handler property.
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets