Chandan Kulkarni wrote:
>
> The spec does sound like you can use the standard types... But...
> Has anyone got a tag with an attribute other than a String to work??
>
> I tried with an int and couldn't get it to work
>
> <tlt:twa attr1='response.getParameter("num")' type="int" />

You're not using the correct syntax for a request-time attribute, see
my original reply below.

> with the TagHandler containing
>
> public void setAttr1(int );
>
> I kept seeing an  error something like:
> Attribute type does not match type defined in tld.
> I am using Apache and Tomcat 3.1

That's because you write the attribute value as a literal string,
not a request-time attribute value. If you fix this it should work.

Hans

> -----Original Message-----
> From: Hans Bergsten <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
> Date: Tuesday, September 26, 2000 11:33 PM
> Subject: Re: taglib attribute question
>
> >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

--
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

Reply via email to