OK -- so it's underspecified. That means that the JRun implementation
is just as correct or incorrect as Tomcat's...

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)'.

-- Oliver

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

Reply via email to