Java Reference
In-Depth Information
The stand-alone API makes use of the javax.el.ELProcessor class to obtain an instance of the ELProcessor for
working with the EL. To use this class, instantiate a new instance and then call upon its methods to utilize different
components of the EL stand alone API. Table 3-4 lists the different methods that can be called upon from an instance
of the ELProcessor class, along with a description of each.
Table 3-4. ELProcessor Methods
Method
Description
defineBean(String, Object)
Defines a variable within the EL environment and assigns
a specified JavaBean to that variable. This makes the bean
available in the local bean repository.
defineFunction(String, String, Method)
Defines an EL function in the local function mapper.
defineFunction(String, String, String, String)
eval(String)
Evaluates an EL Expression.
getELManager()
Returns an EL Manager that can be used for EL Processing.
getValue(String, Class)
Evaluates a given EL expression, coerces it into the
specified type, and returns the result.
setValue(String, Object)
Sets an expression with a value.
setVariable(String, String)
Assigns an EL expression to an EL variable.
Most of the methods that can be called upon from the ELProcessor class can be called upon to work with the EL
processor and achieve the desired effect. The getELManager() method is different in that it returns an instance of the
ELManager class, which allows one to further configure the EL environment. The following sections will further outline
the functionality of the EL Processor.
Defining a Bean
Consider the case where you have a Java class that you would like to make available for use within an EL expression.
The ELProcessor defineBean method can be utilized for doing just that. This method takes two parameters, the first
being a string that will be used to declare the EL variable name, and the second being the JavaBean object that you'd
like to make available from within the EL. The following example demonstrates how to make a bean named TestBean
available for use within an EL context. First, let's take a look at the TestBean source to see that it is a simple JavaBean
that contains no additional extras to facilitate the ELProcessor .
public class TestBean {
private int num1 = 5;
private int num2 = 7;
/**
* @return the num1
*/
public int getNum1() {
return num1;
}
 
 
Search WWH ::




Custom Search