<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

    主站蜘蛛池模板: 在线观看日本亚洲一区| 精品无码国产污污污免费| 最近2019中文免费字幕在线观看| 国产亚洲视频在线观看网址| 亚洲人成色777777老人头| ASS亚洲熟妇毛茸茸PICS| 99999久久久久久亚洲| 一本色道久久88—综合亚洲精品| 亚洲日本国产综合高清| 中文日韩亚洲欧美制服| 亚洲国产精品无码久久98| 亚洲AV成人无码网站| 免费国产高清毛不卡片基地| 人体大胆做受免费视频| 成人A毛片免费观看网站| 免费国产午夜高清在线视频 | 亚洲av综合avav中文| 亚洲国产精品人久久| 亚洲国产韩国一区二区| 亚洲夂夂婷婷色拍WW47| 美女被免费视频网站| 成年免费a级毛片免费看无码| 免费在线观看一级片| 免费精品国偷自产在线在线 | 中国极品美軳免费观看| 亚洲视频免费在线观看| 无人在线观看完整免费版视频| 永久免费观看的毛片的网站| 亚洲无码日韩精品第一页| 亚洲精品无码久久一线| 亚洲成电影在线观看青青| 久久水蜜桃亚洲AV无码精品| 一级毛片在线播放免费| 久久久久久夜精品精品免费啦| 国产成人免费爽爽爽视频| 亚洲 综合 国产 欧洲 丝袜| 亚洲va久久久噜噜噜久久天堂| 亚洲av一本岛在线播放| 特级做a爰片毛片免费看| 久久国产精品免费网站| 免费看www视频|