Unified Expression Language

from Wikipedia, the free encyclopedia

The Java Unified Expression Language is a domain-specific language that is mainly used in Java web applications for embedding expressions in web pages. The authors and expert groups of the Java specifications at the web technology level have developed a standardized expression language for this purpose, which was first integrated in the JSP 2.1 specification (JSR-245) and later referenced in JSR-341 as part of Java EE 7.

history

The Expression Language began as part of the JavaServer Pages Standard Tag Library (JSTL) and was originally called SPEL (Simplest Possible Expression Language), but from now on only called Expression Language ( EL ). It was a scripting language that allowed access to Java components ( JavaBeans ) via JSP . Since JSP 2.0 it has been used within JSP commands to separate Java source code from JSP and to enable easier access to Java components (than using Java code).

Over the years, the Expression Language has evolved, integrated more advanced functionality, and ultimately became part of the JSP 2.0 specification. The creation of scripts has been simplified for web content creators, as they usually have little or no knowledge of the core Java language. This script functionality turned JSP into a script language in the real sense. Before the EL integration, JSP consisted of a few special commands, such as scriptlets, expressions, etc., into which explicit Java source text was inserted. Since the integration of EL, web content creators only need to know how to call up the Java core methods correctly.

EL was similar to JavaScript expressions , both syntactically and semantically :

  • there is no explicit type conversion
  • Typecasts are usually implicit
  • double and single quotes are synonymous
  • object.property has the same meaning as object['property']

EL freed the programmer from knowing the details of how values ​​are actually accessed: object.propertycan mean objecteither object.get("property")or object.getProperty("property")or object.getProperty()etc. (depending on what that is) .

During the development of JSP 2.0, the technology JavaServer Faces was published, which also required an expression language. However, the Expression Language defined in the JSP 2.0 specification did not meet all the requirements necessary for development with JSF. The most obvious limitations were that their expressions were evaluated immediately and that JSF components could not call methods on server-side objects. Therefore, a powerful language was created with the following new properties:

  • Delayed expressions that were not evaluated immediately
  • Expressions that can both read and write data
  • Method expressions that methods can call

The new Expression Language worked well for JSF matters. However, integrating the JSP-EL with the JSF-EL resulted in conflicts. Because of these incompatibilities, the initiative for the Unified Expression Language was started to standardize these Expression Languages. With the JSP 2.1 specification, the expression languages ​​of JSP 2.0 and JSF 1.1 were merged into a single, unified Expression Language (EL 2.1).

Version 3.0 of the Expression Language (which was unified was no longer deemed necessary) was developed in JSR-341 independently of the JSP and JSF specifications. Some new features have been added, most notably the EL equivalents to Streams and Lambda disengaging from Java 8.

particularities

The new unified EL is a combination of the JSP and JSF Expression Languages. In addition to the components already available in JSP EL, the Unified EL supports the following functions:

  • Delayed evaluation
  • Support for expressions that can set values ​​and expressions that can call methods
  • A replaceable API for resolving expressions

Examples

A simple example of the Unified EL as used within a JSTL "c: out" command:

<c:out value="${myBean.myField}" />

An expression that calls a method with one parameter:

${myBean.addNewOrder('orderName')}

Implementations

  • Java Expression Language (JEXL) is a library with the purpose of facilitating the implementation of dynamic and scripting functions for applications and frameworks written in Java. Latest release: Version 3.1, April 14, 2017.
  • JUEL is an open source implementation of the Unified Expression Language (EL), specified as part of the JSP 2.1 standard (JSR-245). It is considered stable and fully functional and is under the Apache License 2.0 . JUEL is also suitable for use in non-JSP applications. Latest release: Version 2.2.7, February 6, 2014.
  • Apache Commons EL is the JSP 2.0 EL interpreter from Apache. Latest release: Version 1.0, June 20, 2003. The links for downloading the source code and the binary files are broken.

See also

  • OGNL - An open source EL used by WebWork (and Struts2).
  • MVEL - An open source EL that is used in many Java-based projects.
  • SpEL - Spring Expression Language, an open source EL that is part of the Spring Framework . It is mainly used in projects in the Spring portfolio, but since it is technology independent it could be used in other projects as well.
  • Ant-Flaka - The project aims to simplify Ant creation scripts using the EL.
  • CEL - An open source EL developed by Google.

Individual evidence

  1. Archived copy . Archived from the original on September 27, 2013. Retrieved September 24, 2013.

External references