Actually, it seems to work with exactly those three setters
mentioned in the example -- I can pass a List in one instance,
and a String in another.
So now I'm wondering whether it's by design or just by accident?...
-- Oliver
Hans Bergsten wrote:
>
> Oliver Suciu wrote:
>
> > OK -- so it's underspecified. That means that the JRun implementation
> > is just as correct or incorrect as Tomcat's...
>
> No. Tomcat is the Reference Implementation, so when in doubt,
> trust Tomcat (yeah, yeah. I know there may be bugs in Tomcat
> as well ;-)
>
> Anyway, this was discussed at length in the spec group. What I
> tell you is the conclusion of how it should work. There may even
> be a blurb about this in the JSP 1.2 spec somewhere. Sorry, but
> I don't have the time to look for it right now.
>
> You believe what you want, of course. I can only tell you that
> if you develop tag handlers with multiple setters, they will
> not work in most containers. I'm just trying to help, not pick
> a fight ;-)
>
> > BTW, there seems to be a simple (JSP- and Tomcat-compliant) way to
> > make use of overloaded setters -- use request-time expressions:
> >
> > modify: <tag setData='string'>
> > to: <tag setData='<%="string"%>'>
> >
> > This bypasses any conversion and correctly invokes the string setter
> > 'public void setData(String dataStr)'.
>
> This only works if the type of the attribute is Object (again,
> just one setter method). In JSP 1.1, yes this is what you have to
> do if you want to assign a String value to the attribute. But it's
> not very "page author friendly", so in JSP 1.2 you can use a literal
> string instead, as in your first example.
>
> Note that Tomcat 4.0 (the RI for JSP 1.2) is buggy in this area.
> It's been fixed in the source, so it should work in the latest
> nightly build.
>
> Hans
>
> > Hans Bergsten wrote:
> >
> >>Oliver Suciu wrote:
> >>
> >>
> >>>You're saying that the spec doesn't say anything about this;
> >>>how comes you then say that the behavior of Tomcat is the
> >>>correct one?...
> >>>
> >>I'm saying that the bean spec does not explicitly say that
> >>a property can not have multiple setter methods, nor that it
> >>can have it. When the spec text is vague, you must look at
> >>the API and the implementation of the bean classes to find
> >>out what to expect. Together they imply that a bean property
> >>can only be associated with one setter method. Look, for
> >>instance, at the java.beans.PropertyDescriptor class. The
> >>constructors allow you to set *one* setter method, and the
> >>getWriteMethod() returns *one* method.
> >>
> >>The bean spec group is aware of this and have indicated to me
> >>that the next rev of the spec will explicitly state this as
> >>well.
> >>
> >>Hans
> >>
> >>
> >>>Hans Bergsten wrote:
> >>>
> >>>
> >>>>Oliver Suciu wrote:
> >>>>
> >>>>
> >>>>
> >>>>>Hi,
> >>>>>
> >>>>>Can anybody help clarify how a JSP container should handle
> >>>>>overloaded setters in a custom tag:
> >>>>>
> >>>>> public void setData(List dataList) {
> >>>>> this.dataList = dataList;
> >>>>> }
> >>>>> public void setData(Object dataObj) {
> >>>>> this.dataObj = dataObj;
> >>>>> }
> >>>>> public void setData(String dataStr) {
> >>>>> this.dataStr = dataStr;
> >>>>> }
> >>>>>
> >>>>>We want to give the JSP author the convenience of passing data
> >>>>>to a tag using different types, whichever comes in more handy.
> >>>>>The data would be of the same "logical" kind, that's why, ideally,
> >>>>>the setters would bear the same name, just like overloaded methods
> >>>>>in Java.
> >>>>>
> >>>>>As an example, JRun 3.1 accepts the code above, whereas Tomcat
> >>>>>3.2.3 throws a CompileException ("Unable to convert a String
> >>>>>to java.util.List").
> >>>>>
> >>>>>What's the correct behavior?
> >>>>>
> >>>>>
> >>>>Tomcat's behavior is correct. When it comes to attribute setter
> >>>>methods, a tag handler class is a "bean", so you must go to the
> >>>>bean spec to see how it deals with property setter methods.
> >>>>The spec text itself doesn't say anything about multiple setter
> >>>>methods, but the implementation of the methods that deal with
> >>>>setter methods only allow one setter method per property. Hence,
> >>>>multiple setter methods for a tag handler attribute is not
> >>>>allowed.
> >>>>
> >>>>In JSP 1.2 you can get around this by making the type of the
> >>>>attribute Object, and the figure out which specific type you
> >>>>got. The reason this only works well with JSP 1.2 is that
> >>>>JSP 1.1 doesn't accept a string literal as the attribute
> >>>>value for an attribute of type Object; JSP 1.2 does.
> >>>>
> >>>> public void setData(Object data) {
> >>>> this.data = data;
> >>>> }
> >>>>
> >>>> public int doStartTag() {
> >>>> if (data instanceof List) {
> >>>> // Work with it as a List
> >>>> }
> >>>> else (data.getClass().isArray()) {
> >>>> // Work with it as an array
> >>>> }
> >>>> else (data instanceof String) {
> >>>> // Work with as a String
> >>>> }
> >>>> else ...
> >>>> }
> >>>>
> >>>>I describe this in more detail in an article that will soon
> >>>>be published at the O'Reilly site. I'll post the URL here
> >>>>when it's available.
> >>>>
> >>>>Hans
> >>>>--
> >>>>Hans Bergsten [EMAIL PROTECTED]
> >>>>Gefion Software http://www.gefionsoftware.com
> >>>>Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com
> >>>>
> >>>>===========================================================================
> >>>>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> >>>>For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
> >>>>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
> >>>>
> >>>>
> >>>===========================================================================
> >>>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> >>>For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
> >>>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
> >>>
> >>>
> >>>
> >>--
> >>Hans Bergsten [EMAIL PROTECTED]
> >>Gefion Software http://www.gefionsoftware.com
> >>Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com
> >>
> >>===========================================================================
> >>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> >>For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
> >>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
> >>
> >
> > ===========================================================================
> > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
> > 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
> >
> >
>
> --
> Hans Bergsten [EMAIL PROTECTED]
> Gefion Software http://www.gefionsoftware.com
> Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
> 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
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
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