風人園

          弱水三千,只取一瓢,便能解渴;佛法無邊,奉行一法,便能得益。
          隨筆 - 99, 文章 - 181, 評論 - 56, 引用 - 0
          數據加載中……

          JSF--Navigate

          JSF中最重要的導航設置
          一、靜態導航
          <h:commandButton label="Login" action="login"/>
          通過action返回的字符串,然后比較   from-outcome標簽值,如果相同,就返回到   to-view-id  制定的頁面
          注: view ID strings must start with a /.
          二、動態導航
          <h:commandButton label="Login" action="#{loginController.verifyUser}"/>
          根據action中調用的bean方法返回值來確定顯示頁面
          loginController的驗證方法
          String verifyUser() {

             if (...)

                return "success";

             else

                return "failure";

          }


          三、高級導航
          Redirection
          如果你在to-view-id 后 加redirect元素,則JSP容器即中斷當前request請求,并發送一個HTTP redirect 請求到client. 
          <navigation-case>
             <from-outcome>success</from-outcome>
             <to-view-id>/success.jsp</to-view-id>
             <redirect/>
          </navigation-case>

          Wildcards(通配符)
          <navigation-rule>
             <from-view-id>/secure/*</from-view-id>
             <navigation-case>
                . . .
             </navigation-case>
          </navigation-rule>
          只要是在/secure/這個目錄下的頁面都使用這個導航規則。

          所有
          <from-view-id>/*</from-view-id>

          or
          <from-view-id>*</from-view-id>

          Using from-action
          <navigation-case>
            <from-action>#{quiz.answerAction}</from-action>
            <from-outcome>again</from-outcome>
            <to-view-id>/again.jsp</to-view-id>
          </navigation-case>
          <navigation-case>
            <from-action>#{quiz.startOverAction}</from-action>
            <from-outcome>again</from-outcome>
            <to-view-id>/index.jsp</to-view-id>
          </navigation-case>
          根據不同的action使用不同的導航規則。

          導航算法

          The algorithm has three inputs(算法有三個輸入):

          • The outcome, that is, the value of an action attribute or the string resulting from the invocation of a method reference. action屬性的值或者引用方法的返回結果(字符串類型)

          • The view ID of the current view。當前視圖

          • The action, that is, the literal value of the action attribute in the component that triggered the navigation.用以觸發導航的組件屬性。

          The first of two phases is to find the matching navigation-rule, following these steps(第二階段的第一步就是尋找符合的導航規則).

          • If the outcome is null, return immediately and redisplay the current page.(如果outcome是空,則立刻返回重新顯示當前頁面)
          • Merge all navigation rules with the same from-view-id value.(合并相同from-view-id的導航規則)
          • Try to find a navigation rule whose from-view-id value matches the view ID exactly. If such a rule exists, take it.
          • Consider all navigation rules whose from-view-id values end with a wildcard suffix, such as secure. For each such rule, check whether the prefix (after removing the *) is identical to the corresponding prefix of the view ID. If there are matching rules, take the one with the longest matching prefix.
          • If there is a rule without a from-view-id, take it.(如果有沒有from-view-id的規則,使用)
          • If there is no match at all, redisplay the current page.(如果都沒有符合,重新顯示當前頁面)

          The second of two phases is to consider all navigation-case elements in the matching navigation rule (which may consist of several merged navigation-rule elements with matching from-view-id.values).

          Follow these steps to find the matching case.

          • If a case has both matching from-outcome and from-action, take it.
          • Otherwise, if a case has matching from-outcome and no from-action, take it.
          • Otherwise, if a case has matching from-action and no from-outcome, take it.
          • Otherwise, if there is a case with neither from-outcome or from-action, take it.
          • If there is no match at all, redisplay the current page.
            Naturally, we recommend that you do not create tricky navigation rules in your own programs. As long as you stay away from wildcards and from-action elements, you won't need to know about the gory details of the navigation algorithm.


           

          posted on 2007-04-26 15:23 風人園 閱讀(586) 評論(0)  編輯  收藏 所屬分類: JSF


          只有注冊用戶登錄后才能發表評論。


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 满洲里市| 田林县| 丽水市| 海宁市| 大兴区| 博白县| 长兴县| 凤山县| 三河市| 神农架林区| 烟台市| 六盘水市| 兴安盟| 禹城市| 延长县| 社会| 监利县| 永川市| 承德市| 金湖县| 阿拉善右旗| 建阳市| 双鸭山市| 邹城市| 潮州市| 南京市| 酉阳| 礼泉县| 盘山县| 天镇县| 岳池县| 临泉县| 酉阳| 江山市| 吉水县| 北辰区| 长乐市| 马尔康县| 凉城县| 涡阳县| 广水市|