You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by bw...@netcourrier.com on 2002/03/12 13:50:49 UTC
simple question
Hi everybody,
I have a simple question :
is it possible to define one tag attributes which can accept 2 types of parameters : Ex String or Object[].
So to do this, i'll try to define 2 setters method:
setMyAttribute(String str){...}
and setMyAttribute(Object[] objectArray){...}
but i'm running into errors, so i would like to know if it's possible and if someone has already done that or not..
Many thanks
Gaetan
----------------------------------------------------------------------
NetCourrier, votre bureau virtuel sur Internet : Mail, Agenda, Clubs, Toolbar...
Web/Wap : www.netcourrier.com
Téléphone/Fax : 08 92 69 00 21 (0,34 E TTC/min - 2,21 F TTC/min)
Minitel: 3615 NETCOURRIER (0,15 E TTC/min - 1,00 F TTC/min)
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: simple question
Posted by Shawn Bayern <ba...@essentially.net>.
On Tue, 12 Mar 2002 bwml@netcourrier.com wrote:
> Hi everybody,
>
> I have a simple question :
> is it possible to define one tag attributes which can accept 2 types of parameters : Ex String or Object[].
> So to do this, i'll try to define 2 setters method:
> setMyAttribute(String str){...}
> and setMyAttribute(Object[] objectArray){...}
>
> but i'm running into errors, so i would like to know if it's possible
> and if someone has already done that or not..
Well, you can always drop back to the one type that String and Object[]
have in common: Object itself. This loses the compile-time type checking
that might otherwise be useful, but it should solve your problem:
setMyAttribute(Object o) {
if (o instanceof String) {
// save it properly
} else if (o instanceof Object[]) {
// save it, differently
} else
throw new IllegalArgumentException("need String or Object[]");
}
Alternatively, you could simple store the object in the accessor method
and process it each time (differentiating String and Object[]) at runtime
in methods like doStartTag().
--
Shawn Bayern
Author, "JSP Standard Tag Library" http://www.jstlbook.com
(coming this spring from Manning Publications)
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>