The Expression Language Syntax

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Java Script Session1 INTRODUCTION.
Expression Language Lec Umair Javed©2006 Generating Dynamic Contents Technologies available  Servlets  JSP  JavaBeans  Custom Tags  Expression.
The Web Warrior Guide to Web Design Technologies
Web applications using JavaServer Faces (JSF) A brief introduction 1JavaServer Faces (JSF)
Road Map Introduction to object oriented programming. Classes
CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.
Internet Technologies 1 Master of Information System Management Java Server Faces Model/View/Controller Design Pattern for Web Development Slides.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
JavaScript, Third Edition
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
JSP Java Server Pages Softsmith Infotech.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
® IBM Software Group © 2007 IBM Corporation JSP Expression Language
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
A Third Look At ML Chapter NineModern Programming Languages, 2nd ed.1.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Tharith Sriv.  JavaScript is a simple programming language that can be written directly into HTML documents to allow for increased interactivity with.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
JavaServer Faces framework Craig McClanahan is presented that created Struts web framework and based on experience gathered designed JavaServer.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
Windows Programming Lecture 03. Pointers and Arrays.
Defects of UML Yang Yichuan. For the Presentation Something you know Instead of lots of new stuff. Cases Instead of Concepts. Methodology instead of the.
Navigation Mimi Opkins CECS 493 Fall Static Navigation  In a simple web application, navigation is static. That is, clicking a particular button.
Intro to JavaServer Faces Mimi Opkins CECS 493 Fall 2016.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Introduction to.
Chapter VII: Arrays.
Definition of the Programming Language CPRL
Event Handling Mimi Opkins CECS 493 Fall 2016.
Chapter 6 JavaScript: Introduction to Scripting
“Under the hood”: Angry Birds Maze
Chapter 4 Client-Side Programming: the JavaScript Language
Expressions and Assignment
JavaScript is a programming language designed for Web pages.
CS 326 Programming Languages, Concepts and Implementation
A lightening tour in 45 minutes
Debugging and Random Numbers
JavaScript Syntax and Semantics
JavaScript: Functions.
Java Review: Reference Types
Chapter 3 Introduction to Classes, Objects Methods and Strings
Week 9 – Lesson 1 Arrays – Character Strings
CS320 Web and Internet Programming Expression Language (EL)
PHP.
JavaScript What is JavaScript? What can JavaScript do?
CISC124 Labs start this week in JEFF 155. Fall 2018
Python Primer 1: Types and Operators
JavaScript What is JavaScript? What can JavaScript do?
CS3220 Web and Internet Programming Expression Language (EL)
Overloading functions
JavaScript CS 4640 Programming Languages for Web Applications
JavaScript Basics What is JavaScript?
Introduction to Computer Science
CS3220 Web and Internet Programming Expression Language (EL)
Review of Previous Lesson
OPERATORS in C Programming
Web Programming and Design
OPERATORS in C Programming
SPL – PS2 C++ Memory Handling.
Presentation transcript:

The Expression Language Syntax Mimi Opkins CECS 493 Fall 2016

Lvalue and Rvalue Modes We start with an expression of the form a.b. For now, we will assume that we already know the object to which a refers. If a is an array, a list, or a map, then special rules apply. If a is any other object, then b must be the name of a property of a. The exact meaning of a.b depends on whether the expression is used in rvalue mode or lvalue mode. This terminology is used in the theory of programming languages to denote that an expression on the right-hand side of an assignment is treated differently from an expression on the left-hand side. Consider the assignment: left = right; A compiler generates different code for the left and right expressions. The right expression is evaluated in rvalue mode and yields a value. The left expression is evaluated in lvalue mode and stores a value in a location.

Lvalue and Rvalue Modes The same phenomenon happens when you use a value expression in a user interface component: <h:inputText value="#{user.name}"/> When the text field is rendered, the expression user.name is evaluated in rvalue mode, and the getName() method is called. During decoding, the same expression is evaluated in lvalue mode and the setName() method is called. In general, the expression a.b in rvalue mode is evaluated by calling the property getter, whereas a.b in lvalue mode calls the property setter.

Using Brackets Just as in JavaScript, you can use brackets instead of the dot notation. That is, the following three expressions all have the same meaning: For example, user.password, user["password"], and user['password'] are equivalent expressions. Why would anyone write user["password"] when user.password is much easier to type? There are a number of reasons: When you access an array or map, the [] notation is more intuitive. You can use the [] notation with strings that contain periods or dashes—for example, msgs["error.password"]. The [] notation allows you to dynamically compute a property: a[b.propname].

Map and List Expressions The value expression language goes beyond bean property access. For example, let m be an object of any class that implements the Map interface. Then m["key"] (or the equivalent m.key) is a binding to the associated value. In rvalue mode, the value m.get("key") is fetched. In lvalue mode, the statement m.put("key", right) is executed. Here, right is the right- hand side value that is assigned to m.key You can also access a value of any object of a class that implements the List interface (such as an ArrayList). You specify an integer index for the list position. For example, a[i] (or, if you prefer, a.i) binds the ith element of the list a. Here i can be an integer, or a string that can be converted to an integer. The same rule applies for array types. As always, index values start at zero.

Evaluating the Value Expression a.b

Calling Methods and Functions You can invoke methods in value expressions. Simply supply the method name and parameters. For example, if the stockQuote bean has a method double price(String), then you can use the following expression: #{stockQuote.price("ORCL")} Overloaded methods are not supported. The bean must have a unique method with the given name. You can also invoke useful functions from the JSTL functions library. They are shown in the next slide. If you use these functions, remember to add xmlns:fn=http://java.sun.com/jsp/jstl/functions to the html element in your page.

JSTL Functions

Resolving the Initial Term Now you know how an expression of the form a.b is resolved. The rules can be applied repetitively to expressions such as a.b.c.d (or, of course, a['b'].c["d"]). We still need to discuss the meaning of the initial term a. In the examples you have seen so far, the initial term referred to a bean or to a message bundle map. Those are indeed the most common situations. But it is also possible to specify other names. There are a number of predefined objects, called implicit objects in the JSF specification. The following table shows the complete list. For example: header['User-Agent'] is the value of the User-Agent parameter of the HTTP request that identifies the user’s browser.

Predefined Objects in the Expression Language

Predefined Objects If the initial term is not one of the predefined objects, the JSF implementation looks for it in the request, view, session, and application scopes, in that order. In particular, all instantiated managed beans are located in these scope maps. If the search is still not successful, the JSF implementation attempts to construct a managed bean or a resource bundle with the given name. Consider, for example, the following expression: #{user.password} The term user is not one of the predefined objects. When it is encountered for the first time, it is not an attribute name in request, view, session, or application scope. Therefore, the JSF implementation locates the managed bean with name user and calls the constructor with no parameters of the corresponding class. Next, it adds an association to the sessionScope map. Finally, it returns the constructed object as the result of the lookup. When the term user needs to be resolved again in the same session, it is located in the session scope.

Composite Expressions You can use a limited set of operators inside value expressions: Arithmetic operators + - * / %. The last two operators have alphabetic variants div and mod. Relational operators < <= > >= == != and their alphabetic variants lt le gt ge eq ne. The first four variants are required for XML safety. Logical operators && || ! and their alphabetic variants and or not. The first variant is required for XML safety. The empty operator. The expression empty a is true if a is null, an array or String of length 0, or a Collection or Map of size 0. The ternary ?: selection operator. Operator precedence follows the same rules as in Java. The empty operator has the same precedence as the unary - and ! operators.

Composite Expressions Generally, you do not want to do a lot of expression computation in web pages—that would violate the separation of presentation and business logic. However, occasionally, the presentation layer can benefit from operators. For example, suppose you want to hide a component when the hide property of a bean is true. To hide a component, you set its rendered attribute to false. Inverting the bean value requires the ! (or not) operator: <h:inputText rendered="#{!bean.hide}" ... /> Finally, you can concatenate plain strings and value expressions by placing them next to each other. Consider, for example: <h:commandButton value="#{msgs.clickHere}, #{user.name}!"/> The statement concatenates four strings: the string returned from #{messages.greeting}, the string consisting of a comma and a space, the string returned from #{user.name}, and the string consisting of an exclamation mark. You have now seen all the rules that are applied to resolve value expressions. Of course, in practice, most expressions are of the form #{bean.property}.

Method Expressions A method expression denotes an object and a method that can be applied to it. For example, here is a typical use of a method expression: <h:commandButton action="#{user.checkPassword}"/> We assume that user is a value of type UserBean and checkPassword() is a method of that class. The method expression is a convenient way of describing a method invocation that needs to be carried out at some future time When the expression is evaluated, the method is applied to the object. In our example, the command button component will call user.checkPassword() and pass the returned string to the navigation handler. Syntax rules for method expressions are similar to those of value expressions. All but the last component are used to determine an object. The last component must be the name of a method that can be applied to that object.

Method Expression Attributes

Method Expression Parameters You can provide parameter values in method expressions. This feature is useful for providing parameters to the actions of buttons and links. For example, <h:commandButton value="Previous" action="#{formBean.move(-1)}"/> <h:commandButton value="Next" action="#{formBean.move(1)}"/> The action method must then be declared with a parameter: When the method reference is evaluated, the parameters are evaluated and passed to the method.