Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Javaee6 JSF Expression Language(EL)

Related Tutorials


 
 

Share on Google+Share on Google+

JSF Expression Language(EL)

Advertisement
In this section, you will get a brief description about Expression Language of JSF.

Expression Language(EL)

In this section, you will get a brief description about Expression Language of JSF.

Expression Language is used to access the JavaBeans component in the JSF web application.

Syntax of EL expression

The syntax of the EL expression is :

# { expression }

It is similar to JSP expression language  but have following differences from it :

  • The syntax of both contains { }curly braces inside it expression resides. But JSP EL starts with $ and JSF EL starts with #.

  • The value binding methods of JSF don't support expression language methods of JSP.

Expression language Literals

The JSF EL supports following literals :

  • Boolean: true and false

  • Integer: as in Java

  • Floating point: as in Java

  • String: with single and double quotes; " is escaped as \", ' is escaped as \', and \ is escaped as \\.

  • Null: null 

Expression language Operators

The Operators supported by JSF EL with operators precedence , from left to right(highest to lowest), is given below :

  • []

  • () (changes precedence of operators)

  • - (unary) not ! empty

  • * / div % mod

  • + - (binary)

  • < > <= >= lt gt le ge

  • = = != eq ne

  • && and

  • || or

  • ? :

Expression language Examples

Some of Example of EL is given below :

JSF EL Expression Result
${1 > (4/2)} false
${4.0 >= 3} true
${100.0 == 100} true
${(10*10) ne 100} false
${?a? < ?b?} true
${?hip? gt ?hit?} false
${4 > 3} true
${1.2E4 + 1.4} 12001.4
${3 div 4} 0.75
${10 mod 4} 2
${!empty param.Add} False if the request parameter named Add is null or an
empty string.
${pageContext.request.contextPath} The context path
${sessionScope.cart.numberOfItems} The value of the numberOfItems property of the
session-scoped attribute named cart.
${param[?mycom.productId?]} The value of the request parameter named
mycom.productId.
${header["host"]} The host
${departments[deptName]} The value of the entry named deptName in the
departments map
${requestScope[?javax.servlet.forward.servlet_path?]} The value of the request-scoped attribute named
javax.servlet.forward.servlet_path
#{customer.lName} Gets the value of the property lName from the customer
bean during an initial request. Sets the value of lName
during a postback
#{customer.calcTotal} The return value of the method calcTotal of the
customer bean.

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 3, 2011

Related Tutorials

Discuss: JSF Expression Language(EL)  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
bbuterbrott
January 31, 2013
Confusing examples

Please correct your examples to use # instead of $, because they are confusing after reading this: "The syntax of both contains { }curly braces inside it expression resides. But JSP EL starts with $ and JSF EL starts with #."
DMCA.com