Show TOC

Function documentationUnified Expression Language Locate this document in the navigation structure

 

Java EE 5 integrates the expression languages of previous versions of JSF and JSP into one Unified Expression Language (EL). With the Unified EL, you can easily access and manipulate application data without using scriptlets or actions. You can dynamically read and write application data, perform arithmetic operations, and invoke static and public methods. EL facilitates the development of scriptless JSP pages. Such JSPs use EL expressions instead of Java scripting.

Features

EL Expressions Syntax

There are two types of syntax for EL expressions. They can be enclosed by the ${ and } characters or by the #{ and } characters. In terms of the JSP life cycle, expressions with the ${ and } syntax are always evaluated immediately and can only appear in template text or as the value of a JSP tag attribute that accepts runtime expressions. Expressions with the #{ and }syntax are always deferred evaluation expressions and are evaluated at a later point. For more information, see Deferred Expressions Evaluation.

EL expressions can either reference data, that is they are value expressions, or invoke methods that return a value, that is they are method expressions. The are two types of value expressions, rvalue expressions and lvalue expressions. Rvalue expressions only read values. Lvalue expressions can both read and write values to external objects. Expressions with the ${ and } syntax are always rvalue expressions, while expressions with the #{ and }syntax can be both rvalue and lvalue expressions.

EL expressions with the ${ and } syntax can be used directly in template text, or in the body of a custom or standard action. For example, you use the JSTL c:out action to print the result of an EL expression to the screen: <c:out value="${myELexpression}"/>. The #{ and }syntax is not allowed for expressions in template text.

You can use both the ${ and } syntax and the #{ and }syntax for EL expressions in tag attribute values. When you use EL expressions in tag attribute values, the Web container processes them differently depending on the attribute's type. For more information, see EL Expressions in Tag Attribute Values.

EL Implicit Objects

To communicate information from the business logic of your application to the JSP pages, you use scoped variables. The EL provides a mechanism to resolve named variables into objects, that is, look up the value of a variable as an attribute. For example, ${employee} will look for an attribute named employee in the page, application, request, and session scopes, and will return its value. The EL also provides a set of implicit objects available for use in EL expressions. For more information, see EL Implicit Objects.

EL Functions

You can define EL functions and invoke them in expressions. EL functions are developed similarly to custom tags. For more information, see Developing EL Functions.