02.JSF Unified EL(表達式)

JSF Unified Expression Language

How to Use it

看似簡單的#{bean.property}, 會因為場合的不同而對應呼叫getter or setter方法, 所以在class裡定義property時, 記得加上getter and setter方法


class Bean{
    private type property;
    public type getProperty(){
        return property;
    public void setProperty(type property){
        this.property = property;

Ex. #{userManagedBean.password}

value="#{userManagedBean.name}, #{userManagedBean.password}" 

Request parameters

Request parameters are now defined in the page itself, using the f:metadata tag. Simply use a f:viewParam to bind each request parameter to a property of your model:
<f:viewParam name="name" value="#{blogSearch.name}"/>
<f:viewParam name="start" value="#{blogSearch.start}"/>

If the parameter value isn't specified in the request then the value will be null, so make sure the property receiving the parameter value isn't a primitive (i.e. it must be nullable). Using request parameters are a great way of achieving bookmarkable URLs, and of developing a stateless application.


隱含物件(implicit object)

<%=request.getContextPath()%>   -> #{request.getContextPath}

  • Note: use [Ctrl + Space] shortcut to call implicit object


  • 算術(Arithmetic): +, - (binary), *, / and div, % and mod, - (unary)
  • 邏輯(Logical): and, &&, or, ||, not, !
  • 關係(Relational): ==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, le. Comparisons can be made against other values, or against boolean, string, integer, or floating point literals.
  • 無(Empty): The empty operator is a prefix operation that can be used to determine whether a value is null or empty.
  • 條件(Conditional): A ? B : C. Evaluate B or C, depending on the result of the evaluation of A.
  • The precedence of operators highest to lowest, left to right is as follows:
    • [] .
    • () (used to change the precedence of operators)
    • - (unary) not ! empty
    • * / div % mod
    • + - (binary)
    • < > <= >= lt(less than) gt(greater than) le(less equal) ge(greater equal)
    • == != eq(equal) ne(not equal)
    • && and
    • || or
    • ? :
  • Note: 在JSF 2.0中, '<', '<=', '&&' 不能被使用, 請用'>', '>=', 'and' 運算子