<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 :: 首頁 ::  :: 聯(lián)系 :: 聚合  :: 管理

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

    Posted on 2010-05-15 19:10 蜀山兆孨龘 閱讀(4077) 評論(0)  編輯  收藏 所屬分類: 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 不再必需。本文介紹并比較了三種途徑來定義可從頁面上的 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 類,并想讓它受管于會話范圍: 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)目,該文件可能會增大到上千行。你還可能會犯拼寫錯(cuò)誤,例如寫錯(cuò) Bean 類名,使你直至運(yùn)行時(shí)才意識到問題。顯然在 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)用到類定義上: 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 {...}
    沒什么特別的,但直截了當(dāng)!用這些標(biāo)注,你就可以從此避免 XML 配置的枯燥和不小心拼錯(cuò)字。然而,這并不是最佳途徑,因?yàn)?JSR 299 中定義的 CDI(用于 Java™ EE 平臺的上下文和依賴注入)提供了類似且強(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)檎缙涿怯糜谝蕾囎⑷氲耐ㄓ每蚣埽簿褪钦f它不但可用于 JSF,還能用于任何其他的 Java EE 6 技術(shù),而且我聽說 Spring 3.0 也將支持它。詳細(xì)的文檔可從 Weld 主頁找到,這里 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.
    主站蜘蛛池模板: 韩国亚洲伊人久久综合影院| 国产特级淫片免费看| av网站免费线看| 日本亚洲色大成网站www久久 | 亚洲自国产拍揄拍| 亚洲欧洲无码AV电影在线观看| 在线视频免费国产成人| 久久精品国产免费观看| 成人性做爰aaa片免费看| 色www免费视频| 亚洲国产精品成人午夜在线观看| 亚洲精品国产福利片| 亚洲av午夜福利精品一区| 久久亚洲中文字幕精品一区| 国产免费小视频在线观看| 欧美最猛性xxxxx免费| 日本黄网站动漫视频免费| 无码人妻丰满熟妇区免费| 国产日韩AV免费无码一区二区三区 | 亚洲成a人片在线不卡一二三区 | 最近中文字幕无免费视频| 1000部禁片黄的免费看| 日韩精品无码一区二区三区免费| 中文字幕在线成人免费看| 亚洲免费一区二区| fc2成年免费共享视频网站| 九九久久精品国产免费看小说| 白白色免费在线视频| 国产精品亚洲а∨无码播放不卡 | 18禁免费无码无遮挡不卡网站| 久久久久国产精品免费看| 日韩免费视频一区二区| 日本高清免费观看| 欧洲精品99毛片免费高清观看| 久久综合九色综合97免费下载| 一区二区免费视频| 99re视频精品全部免费| 久久精品免费一区二区| 妞干网免费观看视频| 在线观看免费亚洲| 亚洲精品视频在线观看你懂的|