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

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

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

    weidagang2046的專欄

    物格而后知致
    隨筆 - 8, 文章 - 409, 評論 - 101, 引用 - 0
    數(shù)據(jù)加載中……

    JSF Navigation by Examples

    JSF Navigation by Examples

    The JavaServer Faces (JSF) Navigation Framework provides navigation rules that allow you to define navigation from view to view (mostly JSP pages) in a Web application. These navigation rules are defined in JSF configuration files along with other definitions for a JSF application. Usually, this file is named faces-config.xml. However, you can assign any other name and even use more than one file to store JSF configuration data. To specify configuration files, use lines like the following in your web.xml file:
    Code:
    <context-param>
    ?<param-name>javax.faces.CONFIG_FILES</param-name>
    ? ? ? <param-value>/WEB-INF/faces-config-navigation.xml,/WEB-INF/faces-beans.xml</param-value>
    </context-param>


    A Simple Example
    The actual construction of a navigation rule is quite simple. Let’s look at our first example:
    Code:
    <navigation-rule>
    ? ? <from-view-id>/pages/inputname.jsp</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>sayHello</from-outcome>
    ? ? ? <to-view-id>/pages/greeting.jsp</to-view-id>
    ? ? </navigation-case>
    ? ? <navigation-case>
    ? ? ? <from-outcome>sayGoodbye</from-outcome>
    ? ? ? <to-view-id>/pages/goodbye.jsp</to-view-id>
    ? ? </navigation-case>
    ? </navigation-rule>
    This code specifies that view /pages/inputname.jsp has two outputs, sayHello and sayGoodbye, associated with particular pages.

    Making a Default Outcome Case
    The basic construction is simple, but there are many variations you can do on the basic construction. Look at the next snippet:
    Code:
    <navigation-rule>
    ? ?<from-view-id>/pages/inputname.jsp</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>sayHello</from-outcome>
    ? ? ? <to-view-id>/pages/greeting.jsp</to-view-id>
    ? ? </navigation-case>
    ? ? <navigation-case>
    ? ? ? <to-view-id>/pages/goodbye.jsp</to-view-id>
    ? ? </navigation-case>
    ? </navigation-rule>
    This code is very similar to the previous example, except that the from-outcome element for the second navigation-case is missing. This means that all outcomes except sayHello, will be forwarded to /pages/goodbye.jsp

    Using Patterns
    The JSF navigation model allows us to use patterns. These patterns consist of a string ending in an asterisk "*". This is shown in the next example:
    Code:
    <navigation-rule>
    ? ? <from-view-id>/pages/*</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>menu</from-outcome>
    ? ? ? <to-view-id>/menu/main_main.jsp</to-view-id>
    ? ? </navigation-case>
    ? ? <navigation-case>
    ? ? ? <from-outcome>info</from-outcome>
    ? ? ? <to-view-id>/menu/info.jsp</to-view-id>
    ? ? </navigation-case>
    ? </navigation-rule>
    This navigation rule will be applied for any page like /pages/exit.jsp that has /pages/ as the beginning of the URL. Note that the asterisk must be located at the end. For example, a pattern such as /pages/*.jsp would not work.

    Resolving More Than One Matching Rule
    Now let’s pay more attention to how rules can be specified in the JSF navigation model. Look at this next example:
    Code:
    <navigation-rule>
    ? ? <from-view-id>/pages/*</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>info</from-outcome>
    ? ? ? <to-view-id>/menu/generalHelp.jsp</to-view-id>
    ? ? </navigation-case>
    ? </navigation-rule>

    ? <navigation-rule>
    ? ? <from-view-id>/pages/login.jsp</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>info</from-outcome>
    ? ? ? <to-view-id>/menu/loginHelp.jsp</to-view-id>
    ? ? </navigation-case>
    ? </navigation-rule>

    In this example, the second navigation rule, not the first rule, will work for outcomes from /pages/login.jsp even though it is also matched by the pattern /pages/* in the first rule. The most specific match of from-view-id always takes precedence for a particular from-outcome.

    "Global" Outcomes
    Let’s say we want the globalHelp outcome from any page to always cause a transition to the page /menu/generalHelp.jsp. For this, we can use either of these two declarations:
    Code:
    <navigation-rule>
    ? ? <from-view-id>*</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>globalhelp</from-outcome>
    ? ? ? <to-view-id>/menu/generalHelp.jsp</to-view-id>
    ? ? </navigation-case>
    </navigation-rule>

    Code:

    <navigation-rule>
    ? ? <navigation-case>
    ? ? ? <from-outcome>globalhelp</from-outcome>
    ? ? ? <to-view-id>/menu/generalHelp.jsp</to-view-id>
    ? ? </navigation-case>
    ? </navigation-rule>

    The first snippet uses an asterisk for the from-view-id element, while the second snippet doesn’t use a from-view-id element at all. Both approaches work the same. Note though, that an empty from-view-id element, as displayed in the snippet below, will not work at all
    Code:
    <navigation-rule>
    ? ?<from-view-id></from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>globalhelp</from-outcome>
    ? ? ? <to-view-id>/menu/generalHelp.jsp</to-view-id>
    ? ? </navigation-case>
    ? </navigation-rule>


    Collision of Rules
    Here is an interesting question. What happens when a couple of navigation rules that have the same from-view-id and the same from-outcome point to different pages. Look at the next example:
    Code:
    <navigation-rule>
    ? ? <from-view-id>*</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>globalhelp</from-outcome>
    ? ? ? <to-view-id>/menu/generalHelp.jsp</to-view-id>
    ? ? </navigation-case>
    ? </navigation-rule>

    <navigation-rule>
    ? ? <from-view-id>*</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>globalhelp</from-outcome>
    ? ? ? <to-view-id>/pages/goaway.jsp</to-view-id>
    ? ? </navigation-case>
    ? </navigation-rule>
    The last rule is always used in such a situation. Also, remember, we spoke at the very beginning of this article about the possibility of splitting JSF configuration data into several files. In the case where the competing rules are in different configuration files, the rule in the last loading configuration file as listed in the web.xml file prevails.

    Spreading Out Parts of a Navigation Rule
    This is one more variation on the same theme. Compare the following snippets:
    Code:
    <navigation-rule>
    ? ? <from-view-id>/pages/inputname.jsp</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>sayHello</from-outcome>
    ? ? ? <to-view-id>/pages/greeting.jsp</to-view-id>
    ? ? </navigation-case>
    ? ? <navigation-case>
    ? ? ? <from-outcome>sayGoodbye</from-outcome>
    ? ? ? <to-view-id>/pages/goodbye.jsp</to-view-id>
    ? ? </navigation-case>
    ? </navigation-rule>


    Code:
    <navigation-rule>
    ? ? <from-view-id>/pages/inputname.jsp</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>sayHello</from-outcome>
    ? ? ? <to-view-id>/pages/greeting.jsp</to-view-id>
    ? ? </navigation-case>
    ?<navigation-rule>
    ?...
    ?...
    ?<navigation-rule>
    ? ? <from-view-id>/pages/inputname.jsp</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>sayGoodbye</from-outcome>
    ? ? ? <to-view-id>/pages/goodbye.jsp</to-view-id>
    ? ? </navigation-case>

    Both snippets produce the same result at run-time. However, the second snippet shows that the declaration can be arbitrarily split up and spread out into different parts of a configuration file or even different configuration files. You can use either approach based on your own preferences.

    Navigation Rules in Action
    Now, it is time to lift the veil a little to see how what we’ve learned can be put to use in an application. A JSP page might contain the following line:
    Code:
    <h:commandButton id="submit" action="sayHello" value="Submit" />

    The action attribute will be used as an outcome. Or, here is another variation:
    Code:
    <h:commandButton id="submit" action="#{GetNameBean.helloAction}" value="Submit" />

    This means that the helloAction method of GetNameBean will be invoked and the result will be used as an outcome. helloAction should be a public method that returns String.
    This distinction between two ways of specifying the action attribute is significant in considering an element in the configuration file we haven’t looked at yet. This is the from-action element. Look at the following code:
    Code:
    ? <navigation-rule>
    ? ?<from-view-id>/pages/inputname.jsp</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>sayHello</from-outcome>
    ? ? ? <to-view-id>/pages/anotherhello.jsp</to-view-id>
    ? ? </navigation-case>
    ? ? <navigation-case>
    ? ? ? <from-action>#{GetNameBean.helloAction}</from-action>
    ? ? ? <from-outcome>sayHello</from-outcome>
    ? ? ? <to-view-id>/pages/hello.jsp</to-view-id>
    ? ? </navigation-case>
    ? </navigation-rule>

    In this code, both navigation cases have the same from-view-id and from-outcome, however the second navigation case includes a from-action element. If the sayHello outcome is determined by GetNameBean.helloAction, the second navigation case will take effect, but only because otherwise both cases had equal precedence.

    Review
    Let’s check how well you understand the material. The page /pages/inputname.jsp has the following declaration for commandButton:
    Code:
    <h:commandButton id="submit" action="#{GetNameBean.helloAction}" value="Submit" />

    The JSF configuration file contains the following code:
    Code:
    <navigation-rule>
    ? ?<from-view-id>/pages/inputname.jsp</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-outcome>sayHello</from-outcome>
    ? ? ? <to-view-id>/a.jsp</to-view-id>
    ? ? </navigation-case>
    ? </navigation-rule>

    <navigation-rule>
    ? ?<from-view-id>/pages/*</from-view-id>
    ? ? <navigation-case>
    ? ? ? <from-action>#{GetNameBean.helloAction}</from-action>
    ? ? ? <from-outcome>sayHello</from-outcome>
    ? ? ? <to-view-id>/b.jsp</to-view-id>
    ? ? </navigation-case>
    ? </navigation-rule>


    If the submit button mentioned above is pressed, what will the next page /a.jsp or /b.jsp if GetNameBean.helloAction returns sayHello?


    from: http://forum.exadel.com/viewtopic.php?t=579

    posted on 2006-03-28 16:23 weidagang2046 閱讀(454) 評論(0)  編輯  收藏 所屬分類: Java

    主站蜘蛛池模板: 日韩欧美一区二区三区免费观看| 中文字幕在线视频免费| 在线视频观看免费视频18| 亚洲av无码一区二区乱子伦as | 亚洲精品国产精品国自产网站 | 曰韩亚洲av人人夜夜澡人人爽| 麻豆安全免费网址入口| 全亚洲最新黄色特级网站| 国产精品公开免费视频| 亚洲大尺度无码无码专线一区| 毛片免费视频播放| 粉色视频成年免费人15次 | 久视频精品免费观看99| 亚洲日本人成中文字幕| 毛片网站免费在线观看| 亚洲JIZZJIZZ妇女| 亚洲国产精品一区二区第一页免| 一区二区三区AV高清免费波多| 久久久久一级精品亚洲国产成人综合AV区 | 精品国产日韩久久亚洲| 永久黄网站色视频免费直播| 免费在线观看一区| 亚洲成色在线综合网站| 免费观看激色视频网站bd | 中文字幕成人免费高清在线 | 老汉色老汉首页a亚洲| 免费很黄无遮挡的视频毛片| 中文字幕日韩亚洲| 99久久人妻精品免费二区| 亚洲一区二区三区久久久久| 免费无码黄网站在线观看| 一级毛片免费观看不收费| 国产成人一区二区三区免费视频| 四虎成人精品国产永久免费无码 | 成年人视频在线观看免费| 狼色精品人妻在线视频免费| 亚洲av永久无码精品秋霞电影影院| 免费H网站在线观看的| 免费看内射乌克兰女| 亚洲精品私拍国产福利在线| 丁香六月婷婷精品免费观看|