風(fēng)人園

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

          JSF--Navigate

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

             if (...)

                return "success";

             else

                return "failure";

          }


          三、高級導(dǎo)航
          Redirection
          如果你在to-view-id 后 加redirect元素,則JSP容器即中斷當前request請求,并發(fā)送一個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/這個目錄下的頁面都使用這個導(dǎo)航規(guī)則。

          所有
          <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>
          根據(jù)不同的action使用不同的導(dǎo)航規(guī)則。

          導(dǎo)航算法

          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屬性的值或者引用方法的返回結(jié)果(字符串類型)

          • 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.用以觸發(fā)導(dǎo)航的組件屬性。

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

          • 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的導(dǎo)航規(guī)則)
          • 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的規(guī)則,使用)
          • 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 風(fēng)人園 閱讀(594) 評論(0)  編輯  收藏 所屬分類: JSF


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


          網(wǎng)站導(dǎo)航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 枞阳县| 本溪市| 晋中市| 乡宁县| 银川市| 衡水市| 红安县| 永安市| 德州市| 和平县| 陆良县| 稷山县| 阜南县| 固阳县| 姜堰市| 衡山县| 西昌市| 安塞县| 南充市| 开化县| 洪洞县| 理塘县| 德安县| 丹阳市| 宜良县| 遂溪县| 乐清市| 奈曼旗| 舞阳县| 敖汉旗| 广饶县| 长顺县| 土默特左旗| 绍兴县| 潜江市| 合作市| 张家口市| 通河县| 古丈县| 石嘴山市| 汝南县|