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

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

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

    神奇好望角 The Magical Cape of Good Hope

    庸人不必自擾,智者何需千慮?
    posts - 26, comments - 50, trackbacks - 0, articles - 11
      BlogJava :: 首頁(yè) ::  :: 聯(lián)系 :: 聚合  :: 管理

    JSF 2.0 中定義受管 Bean 的三種途徑的比較

    Posted on 2010-05-15 19:10 蜀山兆孨龘 閱讀(4086) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Java EE
    JSF 2.0 中定義受管 Bean 的三種途徑的比較 Comparison of Three Ways to Define Managed Beans in JSF 2.0
    JSF 2.0 大量采用標(biāo)注,從而使 web/WEB-INF/faces-config.xml 不再必需。本文介紹并比較了三種途徑來(lái)定義可從頁(yè)面上的 EL 表達(dá)式中引用的受管 Bean。 JSF 2.0 heavily adopts annotations, so web/WEB-INF/faces-config.xml becomes optional. This article introduces and compare three ways to define a managed bean that can be referred in an EL expression on the page.
    現(xiàn)在假設(shè)你有下面這個(gè) Bean 類(lèi),并想讓它受管于會(huì)話范圍: Now assum you have a bean class like this and want it to be managed in session scope:
    1. public class MyManagedBean implements Serializable {...}
    在 JSF 2.0 之前,你需要將它配置到 web/WEB-INF/faces-config.xml 中: Prior to JSF 2.0, you need to configure it in web/WEB-INF/faces-config.xml:
    1. <managed-bean>
    2.     <managed-bean-name>mmb</managed-bean-name>
    3.     <managed-bean-class>com.mycom.MyManagedBean</managed-bean-class>
    4.     <managed-bean-scope>session</managed-bean-scope>
    5. </managed-bean>
    這不僅枯燥,而且難以管理、容易出錯(cuò)。faces-config.xml 不僅用于配置受管 Bean,還用于導(dǎo)航規(guī)則。如果你在做一個(gè)大的互聯(lián)網(wǎng)項(xiàng)目,該文件可能會(huì)增大到上千行。你還可能會(huì)犯拼寫(xiě)錯(cuò)誤,例如寫(xiě)錯(cuò) Bean 類(lèi)名,使你直至運(yùn)行時(shí)才意識(shí)到問(wèn)題。顯然在 JSF 2.0 中,這不是優(yōu)先的途徑。 This is not only tedious but also hard to manage and error prone. faces-config.xml is not only used for configuring managed beans, but also for navigation rules. If you're working with a big web project, this file can grow up to one thousand lines. It's also possible for you to misspell some words, for example the bean class name, that makes you unaware the problem until at runtime. Obviously this way shouldn't be preferred in JSF 2.0.
    第二種途徑由 JSR 314,也就是 JavaServer Faces 2.0 本身提供。你只需將兩個(gè)標(biāo)注應(yīng)用到類(lèi)定義上: The second way is provided by JSR 314, that is JavaServer Faces 2.0 itself. You just apply two annotations onto the class definition:
    1. @javax.faces.bean.ManagedBean(name = "mmb")
    2. @javax.faces.bean.SessionScoped
    3. public class MyManagedBean implements Serializable {...}
    沒(méi)什么特別的,但直截了當(dāng)!用這些標(biāo)注,你就可以從此避免 XML 配置的枯燥和不小心拼錯(cuò)字。然而,這并不是最佳途徑,因?yàn)?JSR 299 中定義的 CDI(用于 Java™ EE 平臺(tái)的上下文和依賴(lài)注入)提供了類(lèi)似且強(qiáng)大得多的標(biāo)注: Nothing special but just nice and straightforward! With these annotations, you're set free from the tedium of XML configuration and carelessness of typo. However, this is still not the best way, because CDI specified in JSR 299 (Contexts and Dependency Injection for the Java™ EE platform) offers similar and far more powerful annotations:
    1. @javax.inject.Named("mmb")
    2. @javax.enterprise.context.SessionScoped
    3. public class MyManagedBean implements Serializable {...}
    為什么要優(yōu)先采用 CDI?因?yàn)檎缙涿?,它是用于依?lài)注入的通用框架,也就是說(shuō)它不但可用于 JSF,還能用于任何其他的 Java EE 6 技術(shù),而且我聽(tīng)說(shuō) Spring 3.0 也將支持它。詳細(xì)的文檔可從 Weld 主頁(yè)找到,這里 Weld 是 JSR 299 的參考實(shí)現(xiàn)。 Why should we prefer CDI? Beacuse as named it's a general purposed framework for dependency injection, which means it can not only used with JSF, but also with any other Java EE 6 tenologies, and I've heard Spring 3.0 will support it too. Detailed documentations can be found at Weld Home, where Weld is the reference implementation for JSR 299.
    主站蜘蛛池模板: 97无码免费人妻超级碰碰碰碰| 国产精品小视频免费无限app| 毛片无码免费无码播放| 亚洲综合久久夜AV | 一级**爱片免费视频| 亚洲精品无码你懂的网站| 免费精品国产自产拍在线观看 | 中文在线免费观看| 奇米影视亚洲春色| 久久国产乱子精品免费女| 亚洲AV福利天堂一区二区三| 最近免费中文字幕中文高清 | 免费人成激情视频在线观看冫| 不卡一卡二卡三亚洲| a级片在线免费看| 亚洲一级二级三级不卡| 久久精品国产免费观看三人同眠 | 亚洲精品日韩中文字幕久久久| 国产成人精品免费视频动漫| 亚洲熟妇少妇任你躁在线观看| 四虎影视在线永久免费看黄| 人成午夜免费大片在线观看| 久久精品国产精品亚洲艾草网| 亚洲视频在线观看免费视频| 亚洲精品美女久久久久久久| 亚洲av无码成人精品区在线播放 | 国产午夜无码视频免费网站| 一级白嫩美女毛片免费| 亚洲精品高清久久| 在线观看免费为成年视频| 美女裸体无遮挡免费视频网站| 久久亚洲国产中v天仙www| 无码区日韩特区永久免费系列| 羞羞视频免费网站含羞草| 久久精品国产精品亚洲色婷婷| 无码中文在线二区免费| 国产精品内射视频免费| 亚洲另类自拍丝袜第1页| 免费人成视频x8x8入口| 91香蕉在线观看免费高清| 亚洲AV无码专区在线厂|