On Tue, 12 Mar 2002 [EMAIL PROTECTED] 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: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>