Java Reference
In-Depth Information
Defining a Function
If you wish to assign a Java-based function to an EL expression variable, you can do so by calling one of the
ELProcessor defineFunction methods. These two methods both achieve the same result, but they each accept
different parameters to get there. First, you can call the defineFunction(String, String, Method) function by
passing the following parameters:
String-based prefix (Java package) that should be utilized to fully qualify the function
String-based name of the Java class that contains the method you would like to assign to the
function
The second defineFunction method accepts four String-based parameter values, those being the following:
Method object that you'd like to invoke
Prefix (Java package) that should be utilized to fully qualify the function
Name identifier to which you would like to assign the method call
Name of the Java class that contains the method that you would like to assign to the function
The following lines of code demonstrate how to define a function named obtainMessage to a Java-based method
named obtainMessage , which belongs within the TestBean class.
Name of the static Java method to utlize
ELProcessor el = new ELProcessor();
try {
el.defineFunction("org", "obtainMessage", "org.javaee7.chapter03.el.client.TestBean",
"obtainMessage");
} catch (ClassNotFoundException|NoSuchMethodException ex) {
// handle error
}
Object result = el.eval("org:obtainMessage()");
Utilizing the ELManager
The ELManager class can be used to set configurations for the EL environment. For instance, it can be used to import
Java packages or classes for use within EL expressions. Table 3-5 lists the methods that can be useful within the
ELManager for configuring the EL environment. It should be noted that some of the methods mirror those that are
available from the ELProcessor .
 
Search WWH ::




Custom Search