Version 5

    Expression Language FAQ

     

    What is an Expression Language (EL)?

    The Java EL 2.1 specification defines an Expression Language as "(a language that) makes it easy for page authors to access and manipulate application data without having to master the complexity associated with programming languages such as Java and JavaScript."  In practice, the Java EL provides a shorthand way to look up JavaBeans, call getters, call setters, and call other methods.

     

    There are other Expression Languages, but this FAQ only deals with the EL as defined by various Java JSRs.

     

    How about an example?

    Say I have a Person JavaBean with a "name" property.  It would have methods getName() and setName(String name).  Also assume that an instance of this JavaBean lives in some scope such as session scope or application scope.  The instance is bound to the name "employee".  I could refer to the name property like this:

    ${employee.name} 

     

    If "Name" were a class instead of a simple String, I could make the expression longer to get to its parts:

    First Name: ${employee.name.firstname}
    Last Name: ${employee.name.lastname}
    

     

    If I use this with a technology such as JSF, I can refer to it in a JSF tag like this:

    <h:inputText value="#{employee.name}"></h:inputText>

    In this case, JSF is responsible for using the expression to retrieve the value of "name" when the page is displayed and set the value of "name" when the page is submitted.

     

    What else can the EL do?

    Besides referring to getters, setters, and other methods, the EL has the ability to evaluate arithmetic and boolean expressions:

    ${employee.salary > 50000} 
    ${employee.salary * tax.rate} 
    ${employee.spouse == Empty} 
    ${employee.name.firstname == 'Fred'} 

     

    What are the Java EL specifications?

    There are three different EL specifications.

    The EL's for JSP 2.0 and JSF 1.1 were not compatible.  The Unified EL brings these EL's together under one specification.  The Unified EL was created by the JSP 2.1 expert group (JSR-245), but it is its own specification.

     

    What technologies use which EL?

    JSP 2.0

    JSP EL

    JSP 2.1

    Unified EL

    JSF 1.1

    JSF EL

    JSF 1.2

    Unified EL

    JSTL 1.1

    JSP EL

    JSTL 1.2

    Unified EL

    Facelets

    Unified EL

    Seam

    Depends on which view technology is used (JSP or Facelets)

     

    Why do some expressions start with { and others start with ${ ?