<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sealyu

    --- 博客已遷移至: http://www.sealyu.com/blog

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks
    JSF的表達(dá)式語言(EL)的形式跟jSP的表達(dá)式語言的形式類似:#{...}。EL的主要用途是使你可以引用和更新bean的屬性,或者執(zhí)行簡單的語句,而不用寫完整的Java代碼。
    l JSF EL基于JSP 2.0中的表達(dá)式語言,它的用法幾乎跟JSP2.0中的表達(dá)式語言一樣,但二者仍有一些關(guān)鍵不同:
    l JSF使用(#)來標(biāo)記表達(dá)式的開始,而JSP使用($);
    JSF表達(dá)式是雙向的。即它可以引用屬性的值也可以更新之
    l JSF EL也允許引用對象方法;
    l 某些JSP特定的特征無效,比如頁面上下文范圍(page);
    l JSF EL表達(dá)式可以通過常規(guī)Java代碼求解(結(jié)果是可以不需要JSP);
    l JSF EL不官方支持函數(shù)。
    JSF EL也支持“.”和“[]”取值。它支持全范圍的算術(shù)運(yùn)算、邏輯運(yùn)算與關(guān)系運(yùn)算:
    1.      算術(shù)運(yùn)算有:
    加法 (+), 減法 (-), 乘法 (*), 除法 (/ or div) 與余除 (% or mod) 。下面是算術(shù)運(yùn)算的一些例子:
    表達(dá)式
    結(jié)果
    #{1}
    1
    #{1 + 2}
    3
    #{1.2 + 2.3}
    3.5
    #{1.2E4 + 1.4}
    12001.4
    #{-4 - 2}
    -6
    #{21 * 2}
    42
    #{3 / 4}
    0.75
    #{3 div 4}
    0.75,除法
    #{3 / 0}
    Infinity
    #{10 % 4}
    2
    #{10 mod 4}
    2,也是求模
    #{(1 == 2) ? 3 : 4}
    4
    如同在Java語法一樣 ( expression ? result1 : result2)是個(gè)三元運(yùn)算,expressiontrue顯示result1false顯示result2
    2. 邏輯運(yùn)算:
    and(&&)or(!!)not(!)。一些例子為:
    表達(dá)式
    結(jié)果
    #{true and false}
    false
    #{true or false}
    true
    #{not true}
    false
    3. 關(guān)系運(yùn)算:
    小于Less-than(<、lt)、大于Greater-than (>、gt)、小于或等于Less-than-or-equal(<=、le)、大于或等于Greater-than-or-equal(& gt;=、ge)、等于Equal(==、eq)、不等于Not Equal(!=、ne),由英文名稱可以得到lt、gt等運(yùn)算子之縮寫詞,以下是一些例子:
    表達(dá)式
    結(jié)果
    #{1 < 2}
    true
    #{1 lt 2}
    true
    #{1 > (4 / 2)}
    false
    #{1 > (4 / 2)}
    false
    #{4.0 >= 3}
    true
    #{4.0 ge 3}
    true
    #{4 <= 3}
    false
    #{4 le 3}
    false
    #{100.0 == 100}
    true
    #{100.0 eq 100}
    true
    #{(10 * 10) != 100}
    false
    #{(10 * 10) ne 100}
    false
    關(guān)系運(yùn)算也可以用來比較字符或字符串,按字典順序來決定比較結(jié)果,例如:
    表達(dá)式
    結(jié)果
    #{'a' < 'b'}
    true
    #{'hip' > 'hit'}
    false
    #{'4' > 3}
    true
    4. Empty
    用來測試空值(null、空字符串、數(shù)組、Map或者沒有值的Collection),如:
    表達(dá)式
    結(jié)果
    #{empty ''}
    true
    #{empty 'abcd'}
    false
    JSF EL能搜索Java Web應(yīng)用的三個(gè)范圍:application、session、request中以匹配特定關(guān)鍵字的對象。因?yàn)镴SF一定要鎖定到JSP,所以它不支持 page范圍。JSF EL支持的隱含變量有:cookie、header、headerValues、initParam、param、paramValues、 applicationScope、sessionScope、requestScope、還有facesContext(當(dāng)前請求的 FacesContext實(shí)例)和view(當(dāng)前視圖)。




    JavaServer Faces Expression Language

    See Also

    This topic is for advanced users who want to enter their own value binding expressions rather than letting the IDE create those expressions. It has the following sections:

    Introduction
    JavaServer Faces EL Expression Syntax
    Get Value Semantics
    Set Value Semantics
    Implicit Objects
    Literals
    Operators
    Reserved Words

    Introduction

    JavaServer Faces provides an expression language (JSF EL) that is used in web application pages to access the JavaBeans components in the page bean and in other beans associated with the web application, such as the session bean and the application bean. The IDE in most cases takes care of specifying the correct expression for you, for example, when you bind a component's text property to a data provider or to a JavaBean property.

    To bind any property of a component, you can add the component to a page and then right-click the component and choose Property Bindings. You can then use the Property Bindings dialog box to select a property of the component and choose which JavaBeans property the component property is to be bound to.

    As an example of binding a component to a database table, the following code sample references a Static Text component. Here's how to produce the code sample:

    1. Drag the Static Text component output text icon from the Basic category of the Palette to a page in the Visual Designer.
       
    2. Open the Servers window and drag the Person table from the Travel database and drop it on the component.
       
      The IDE automatically adds a data provider object for that database table to the page and binds the the text property to the PERSON.PERSONID field of the data provider. You see the text of the component change to 123.
    3. Right-click the component and choose Bind to Data.
       
    4. In the Bind to Data dialog box, choose the PERSON.NAME field of the data provider and click OK to change the binding of the text property to the correct field.
       
    5. Click the JSP button above the page to see the resulting source code.
       

    The resulting code in the JSP editor looks like this:

      <ui:staticText binding="#{Page1.staticText1}" 

    id="staticText1"

    style="position: absolute; left: 216px; top: 192px"

    text="#{Page1.personDataProvider.value['PERSON.NAME']}"/>
    • The first line of code shows the name of the JavaServer Faces component, staticText. It uses the qualifier ui:, which identifies the XML namespace for the staticText component. The ui: qualifier is defined in the page header as xmlns:ui="http://www.sun.com/web/ui". This namespace points to a custom tag library for rendering UI components in the Basic, Composite, and Layout categories of the Palette.
       
      There are two other qualifiers that you will see in JSP code that are defined on this same line :
      • h: - Defined in the page header as xmlns:h="http://java.sun.com/jsf/html", this namespace points to a JavaServer Faces custom tag library for rendering JavaServer Faces Reference Implementation components that are primarily in the Standard category of the palette.
         
      • f: - Defined in the page header as xmlns:f="http://java.sun.com/jsf/core", this namespace points to a JavaServer Faces custom tag library for representing event handlers, validators, and other actions.
         

      The TLD documentation for these two qualifiers is located at:
      http://java.sun.com/j2ee/javaserverfaces/1.1/docs/tlddocs/index.html.


       
    • The binding attribute connects this component to a specific JavaBeans object staticText1 in the Page1 page bean. The binding attribute and the attributes id, style, and text are all JavaServer Faces tag library attributes. The last three attributes, id, style, and text, are represented in the IDE as properties of the component and can be set in the component's Properties window.
       
    • The binding and text attributes use the JavaServer Faces expression language. You can use the JavaServer Faces expression language to set the value attribute in the component's Properties window.
       

    As described in the sections that follow, the JavaServer Faces expression language syntax uses the delimiters #{}. A JavaServer Faces expression can be a value-binding expression (for binding UI components or their values to external data sources) or a method-binding expression (for referencing backing bean methods). It can also accept mixed literals and the evaluation syntax and operators of the 2.0 expression language.

    JavaServer Faces EL Expression Syntax

    JSF EL can be used to bind JavaBeans to component properties to simplify how the components access data from various sources. JSF EL expressions use the syntax #{expr};

    The syntax of a value binding expression is identical to the syntax of an expression language expression defined in the JavaServer Pages Specification (version 2.0), sections 2.3 through 2.9, with the following exceptions:

    • The expression delimiters for a value binding expression are #{ and } instead
      of ${ and }.
       
    • Value binding expressions do not support JSP expression language functions.
       

    In addition to the differences in delimiters, the two expression types have the following semantic differences:

    • During rendering, value binding expressions are evaluated by the JavaServer Faces implementation (via calls to the getValue method) rather than by the compiled code for a page.
       
    • Value binding expressions can be evaluated programmatically, even when a page is not present.
       
    • Value binding expression evaluation leverages the facilities of the configured VariableResolver and PropertyResolver objects available through the Application object for the current web application, for which applications can provide plug-in replacement classes that provide additional capabilities.
       
    • If a value binding expression is used for the value property of an EditableValueHolder component (any input field component), the expression is used to modify the referenced value rather than to retrieve it during the Update Model Values phase of the request processing lifecycle.
       

    Examples of valid value binding expressions include:

       #{Page1.name}

    #{Foo.bar}

    #{Foo[bar]}

    #{Foo[“bar”]}

    #{Foo[3]}

    #{Foo[3].bar}

    #{Foo.bar[3]}

    #{Customer.status == ‘VIP’}

    #{(Page1.City.farenheitTemp - 32) * 5 / 9}

    Reporting Period: #{Report.fromDate} to #{Report.toDate}

    For value binding expressions where the setValue method is going to be called (for example, for text property bindings for input fields during Update Model Values), the syntax of a value binding expression is limited to one of the following forms, where expr-a is a general expression that evaluates to some object, and value-b is an identifier:

       #{expr-a.value-b}

    #{expr-a[value-b]]

    #{value-b}

    Get Value Semantics

    When the getValue method of a ValueBinding instance is called (for example, when an expression on a JSP tag attribute is being evaluated during the rendering of the page), and the expression is evaluated, and the result of that evaluation is returned, evaluation takes as follows:

    • The expression language unifies the treatment of the . and [] operators. expr-a.expr-b is equivalent to a["expr-b"]; that is, the expression expr-b is used to construct a literal whose value is the identifier, and then the [] operator is used with that value.
       
    • The left-most identifier in an expression is evaluated by the VariableResolver instance that is acquired from the Application instance for this web application. If the value on the left side of the . or [] operator is a RowSet, the object on the right side is treated as a column name. See the next section for a more complete evaluation description of these operators.
       
    • Each occurrence of the . or [...] operators in an expression is evaluated by the PropertyResolver instance that is acquired from the Application instance for this web application.
       

    •  
      Properties of variables are accessed by using the . operator and can be nested arbitrarily.
       

    Set Value Semantics

    When the setValue method of a ValueBinding is called (for example, for text property bindings for input fields during Update Model Values), the syntax of the value binding restriction is restricted as described in the previous section. The implementation must perform the following processing to evaluate an expression of the form #{expra.value-b} or #{expr-a[value-b]}:

    • Evaluate expr-a into value-a.
       
    • If value-a is null, throw PropertyNotFoundException.
       
    • If value-b is null, throw PropertyNotFoundException.
       
    • If value-a is a Map, call value-a.put(value-b, new-value).
       
    • If value-a is a List or an array:
      • Coerce value-b to int, throwing ReferenceSyntaxException on an error.
         
      • Attempt to execute value-a.set(value-b, new-value) or Array.set(value-b, new-value) as appropriate.
         
      • If IndexOutOfBoundsException or ArrayIndexOutOfBoundsException is thrown, throw PropertyNotFoundException.
         
      • If a different exception was thrown, throw EvaluationException.
         

       
    • Otherwise (value-a is a JavaBeans object):
      • Coerce value-b to String.
         
      • If value-b is a writeable property of value-a (as per the JavaBeans Specification), call the setter method (passing new-value). Throw ReferenceSyntaxException if an exception is thrown.
         
      • Otherwise, throw PropertyNotFoundException.
         

       

    If the entire expression consists of a single identifier, the following rules apply:

    • If the identifier matches the name of one of the implicit objects described below,
      throw ReferenceSyntaxException.
       
    • Otherwise, if the identifier matches the key of an attribute in request scope,
      session scope, or application scope, the corresponding attribute value will be
      replaced by new-value.
       
    • Otherwise, a new request scope attribute will be created, whose key is the
      identifier and whose value is new-value.
       

    Implicit Objects

    The expression language defines a set of implicit objects:

    • facesContext - The FacesContext instance for the current request.
       
    • param - Maps a request parameter name to a single value.
       
    • paramValues - Maps a request parameter name to an array of values.
       
    • header - Maps a request header name to a single value.
       
    • headerValues - Maps a request header name to an array of values.
       
    • cookie - Maps a cookie name to a single cookie.
       
    • initParam - Maps a context initialization parameter name to a single value.
       

    Objects that allow access to various scoped variables:

    • requestScope - Maps request-scoped variable names to their values.
       
    • sessionScope - Maps session-scoped variable names to their values.
       
    • applicationScope - Maps application-scoped variable names to their values.
       

    When an expression references one of these objects by name, the appropriate object is returned. An implicit object takes precedence over an attribute that has the same name. For example, #{facesContext} returns the FacesContext object, even if there is an existing facesContext attribute containing some other value.

    Literals

    The expression language defines the 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
       

    Operators

    In addition to the . and [] operators discussed above in Get Value Semantics and the section after that one, the expression language provides the following operators:

    • Arithmetic: +, - (binary), *, /, div, %, 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:

    • [] .
       
    • ()  (changes precedence of operators)
       
    • - (unary) not ! empty
       
    • * / div % mod
       
    • + - (binary)
       
    • < > <= >= lt gt le ge
       
    • == != eq ne
       
    • && and
       
    • || or
       
    • ? :
       

    Reserved Words

    The following words are reserved for the expression language and must not be used as identifiers:

    and false le not
    div ge lt null
    empty gt mod or
    eq instanceof ne true
    See Also
    About the JSP Editor
    Adding Components to a Page
    About Binding Components to Data
    Binding Component Properties
    About Pages

    posted on 2009-02-24 16:02 seal 閱讀(2782) 評論(0)  編輯  收藏 所屬分類: Seam
    主站蜘蛛池模板: 免费人成视频x8x8入口| 亚洲av永久无码精品网站| 美女被暴羞羞免费视频| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 四虎影视在线永久免费看黄| www成人免费视频| 中文字幕亚洲综合久久2| 精品剧情v国产在免费线观看 | 亚洲精品国产品国语在线| 国产99视频精品免费观看7| 边摸边吃奶边做爽免费视频网站 | 精品国产麻豆免费人成网站| 国产色在线|亚洲| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 国产精品免费视频观看拍拍| 亚洲国产成人va在线观看网址| 国产免费131美女视频| 97精品免费视频| 暖暖免费中文在线日本| 亚洲大香伊人蕉在人依线| 国产专区一va亚洲v天堂| 永久免费的网站在线观看| 中文在线观看国语高清免费| 91在线亚洲综合在线| 久久99国产亚洲精品观看| 四虎影永久在线高清免费| 18勿入网站免费永久| 国产一级黄片儿免费看| 爱情岛论坛亚洲品质自拍视频网站 | 激情无码亚洲一区二区三区 | 国产裸体美女永久免费无遮挡 | 99亚洲精品卡2卡三卡4卡2卡| 亚洲黄色免费电影| 中国亚洲女人69内射少妇| 麻豆成人精品国产免费| 精品福利一区二区三区免费视频| 最近更新免费中文字幕大全| 特级毛片爽www免费版| 国产精品亚洲专区无码WEB| 亚洲最大福利视频| 亚洲免费视频观看|