The Java EE 5 Tutorial


The JSP expression language allows you to define a function that can be invoked in an expression. Functions are defined using the same mechanisms as custom tags (see Using Custom Tags and Chapter 8, Custom Tags in JSP Pages).

At first glance, functions seem similar to method expressions, but they are different in the following ways:

Using Functions

Functions can appear in static text and tag attribute values.



                localeString)}" >



Defining Functions

To define a function, program it as a public static method in a public class. The mypkg.MyLocales class in the date example defines a function that tests the equality of two Strings as follows:

package mypkg;
public class MyLocales {

    public static boolean equals( String l1, String l2 ) {
        return l1.equals(l2);

Then map the function name as used in the EL expression to the defining class and function signature in a TLD (see Chapter 8, Custom Tags in JSP Pages). The following functions.tld file in the date example maps the equals function to the class containing the implementation of the function equals and the signature of the function:

    <function-signature>boolean equals( java.lang.String,
        java.lang.String )</function-signature>

No two functions within a tag library can have the same name.