> -----Original Message-----
> From: Hans Bergsten [mailto:[EMAIL PROTECTED]]
> Sent: Monday, October 14, 2002 3:26 PM
> To: Tag Libraries Users List
> Subject: Re: Beefing up JSTL EL in JSP 2
>
>
> Martin Cooper wrote:
> >
> >>-----Original Message-----
> >>From: Hans Bergsten [mailto:[EMAIL PROTECTED]]
> >>
> >>Shawn is rarely wrong, but here actually missed one detail:
> >>JSP 2.0 adds
> >>_functions_ to the EL, but not _methods_ as is used in this example.
> >>A function is a method on a specific class, declared in the
> >>TLD. It can
> >>then be used in an EL expression like this:
> >>
> >> ${mylib:customer(mybean, pageScope.range * 2)}
> >
> >
> > How would this map back to Java code? Is there any inferred
> relationship
> > between 'customer' and the method being called, and between
> 'mybean' and the
> > class on which the method is being invoked?
>
> Note that it's a "function" call, not a "method" call; a "function" is
> not targetted to a specific object, as a method is, so all
> info must be
> passed as parameters.
>
> "mylib" is the prefix assigned to the taglib that contains
> the function
> declaration.
> "customer" is the function name declared in the TLD, and "mybean" is
> an variable of the type declared for the customer() functions first
> parameter.
>
> Does that help?
A bit, but the part below helped more. ;-)
This particular distinction between functions and methods seems to be a
rather JSTL-specific view, which isn't clear until you already know what it
means. In general, a function is simply a procedure/routine/method that
returns a value. It might be static (i.e. not associated with an object) or
it might not.
Java doesn't have functions, it has methods. You won't find the JLS talking
about functions. Saying that an expression in the EL is 'a "function" call,
not a "method" call' is confusing, because it is, in fact, a method call,
since that's all Java has. It's just that the method (a) must return a value
(thus making it a function), and (b) must be static.
I guess what I'm saying is that the terminology is very confusing. If we
could get away from talking about methods *as opposed to* functions, I think
that would clear things up a lot.
By the way, FWIW, I am +1000 on having functions and *not* methods (!) in
JSTL/JSP.
--
Martin Cooper
>
> > The syntax above seems to imply that, at least in this
> case, 'mybean'
> > corresponds to 'this'. I'm guessing that the method name
> need bear no
> > relation to the function name used in JSP, and that the
> mapping is specified
> > in the TLD? What about calling static methods?
> >
> > I guess I should really go read the spec...
>
> Yes :-) But here's what the JSP 2.0 PFD says:
>
> JSP.2.6.2 Tag Library Descriptor Information
> Each tag library may include zero or more n-ary (static) functions.
> The Tag Library Descriptor (TLD) associated with a tag
> library lists
> the functions. Each such function is given a name (as seen
> in the EL),
> and a static method in a specific class that will implement the
> function. The class specified in the TLD must be a public
> non-abstract
> class. The specified method must be a public static method in the
> specified class. [...]
>
> JSP.2.6.3 Example
> The following TLD fragment describes a function with name nickname
> that is intended to fetch the nickname of the user:
>
> <taglib>
> ...
> <function>
> <name>nickname</name>
> <function-class>mypkg.MyFunctions</function-class>
> <function-signature>String
> nickName(String)</function-signature>
> </function>
> </taglib>
>
> The following EL fragment shows the invocation of the function:
>
> <h2>Dear ${my:nickname(user)}</h2>
>
> Hans
> --
> Hans Bergsten [EMAIL PROTECTED]
> Gefion Software http://www.gefionsoftware.com
> JavaServer Pages http://TheJSPBook.com
>
>
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>