2008.02.09 摘自 JSF in action 2.4 Exploring the JSF expression language Page/110
Table 2.3 You can use the JSF EL to wire components to objects that expose JavaBean properties,
collections, and simple data types. The EL can also be used to reference methods and create logical
or numeric statements. In addition, nested properties are supported.
Example | Description |
---|---|
#{myBean.value} | Returns the value property of the object stored under the key myBean, or the element stored under the key value if myBean is a Map. |
#{myBean['value']} | Same as "{#myBean.value}". |
#{myArrayList[5]} | Returns the fifth element of a List stored under the key myArrayList. |
#{myMap['foo']} | Returns the object stored under the key foo from the Map stored under the key myMap. |
#{myMap[foo.bar]} | Returns the object stored under the key that equals the value of the expression foo.bar from the Map stored under the key myMap. |
#{myMap['foo'].value} | Returns the value property of the object stored under the key foo from the Map stored under the key myMap. |
#{myMap['foo'].value[5]} | Returns the fifth element of the List or array stored under the key foo from the Map stored under the key myMap. |
#{myString} | Returns the String object stored under the key myString. |
#{myInteger} | Returns the Integer object stored under the key myInteger. |
#{user.role == 'normal'} | Returns true if the role property of the object stored under the key user equals normal. Returns false otherwise. |
#{(user.balance - 200) == 0} | If the value of the balance property of the object stored under the key user minus 200 equals zero, returns true. Returns false otherwise. |
Hello #{user.name}! | Returns the string "Hello" followed by the name property of the object stored under the key user. So if the user’s name is Sean, this would return "Hello Sean!" |
You are #{(user.balance > 100) ? 'loaded' : 'not loaded'} | Returns the string "You are loaded" if the balance property of the object stored under the key user is greater than 100; returns "You are not loaded" otherwise. |
#{myBean.methodName} | Returns the method called method of the object stored under the key myBean. |
#{20 + 3} | Returns 23. |