scwcd_notes

Page 29

EL operators EL provides two navigation operators : The dot operator; The [ ] operator. dot operator Syntax : leftVariable.rightVariable

The dot operator is simple and restrictive. The rules of the dot operator are :

a variable on the left of a dot is : o a Map; o a bean. a variable on the right of a dot is : o a map key; o a bean property.

The name of the right hand side variable must respect Java naming conventions : starts with a letter, a $, or a _ after first character, digits may be used can’t be a java keyword. [] operator Syntax : leftVariable[“content”]

Rules are : a variable on the left of the [] may be : o a Map; o a bean; o a List; o an array. the content of the [] may be : o a Map key; o a bean property; o an index into a List; o an index into an array. For indices into Lists/arrays, the quotes can be omitted : myList[2]

If quotes are used with indices, the String index is automatically coerced into an int : myList[“2”]

If content is a String and quotes are NOT used, EL assumes it’s an attribute and replaces it by its value, or by null if it’s not found. toto[titi] titi : assumed to be an attribute >> will be evaluated.

EXAM NOTE : Watch out quote vs no quotes !!! The [] operator allows nested expressions. Evaluation is made from inner most [] outer. ${titi[toto[foo[bar]]]}

29


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.