<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
    主站蜘蛛池模板: 亚洲日韩精品一区二区三区| 国产成人高清精品免费软件| 亚洲AV无码专区国产乱码电影 | 亚洲精品国产精品国自产网站| 精品无码无人网站免费视频| 亚洲午夜久久影院| 无码国产精品一区二区免费3p | xvideos亚洲永久网址| 国产偷国产偷亚洲高清人 | 亚洲国产精品国自产拍AV| a级毛片在线免费| 久久精品国产亚洲av麻豆 | 色偷偷亚洲第一综合网| 免费成人在线观看| 抽搐一进一出gif免费视频| 亚洲AV永久精品爱情岛论坛| 鲁大师在线影院免费观看 | 久久被窝电影亚洲爽爽爽| 久别的草原电视剧免费观看| 亚洲色图.com| 日本免费一区尤物| 精品乱子伦一区二区三区高清免费播放| 亚洲毛片αv无线播放一区| 最好看的中文字幕2019免费| 亚洲无码一区二区三区| 亚洲中文字幕成人在线| 麻豆成人久久精品二区三区免费 | 一个人免费播放在线视频看片 | 亚洲色欲一区二区三区在线观看| 一级毛片免费不卡在线| 亚洲中文字幕一二三四区| 2048亚洲精品国产| 最近免费中文字幕大全免费| 亚洲国产欧洲综合997久久| 国产精品亚洲片在线| 日本XXX黄区免费看| 一级做a爱过程免费视频高清| 亚洲午夜在线电影| 国产一区二区视频免费| 久久午夜伦鲁片免费无码| 国产亚洲精品AAAA片APP|