?? 導航規則設置.htm
字號:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建網頁 1</title>
</head>
<body>
<p>導航規則設置</p>
<div id="PageContent">
<table cellSpacing="0" cellPadding="0" width="100%" border="0" id="table3">
<tr>
<td class="pagebody" vAlign="top">
<table style="CLEAR: both" cellSpacing="0" cellPadding="0" width="100%" border="0" id="table4">
<tr>
<td class="pagecontent" vAlign="top" width="100%">
<div class="wiki-content">
在JSF中是根據faces-config.xml中<navigation-rule>設定,以決定在符合的條件成立時,該連結至哪一個頁面,一個基本的設定如下:<div class="code" style="BORDER-TOP-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-BOTTOM-STYLE: solid">
<div class="codeContent">
<pre class="code-java">....
<navigation-rule>
<from-view-id>/pages/index.jsp</from-view-id>
<navigation-<span class="code-keyword">case</span>>
<from-outcome>success</from-outcome>
<to-view-id>/pages/welcome.jsp</to-view-id>
</navigation-<span class="code-keyword">case</span>>
<navigation-<span class="code-keyword">case</span>>
<from-outcome>failure</from-outcome>
<to-view-id>/pages/index.jsp</to-view-id>
</navigation-<span class="code-keyword">case</span>>
</navigation-rule>
....</pre>
</div>
</div>
<p> 對于JSF,每一個視圖(View)都有一個獨特的識別(identifier),稱之為View ID,在JSF中的View
ID是從Web應用程序的環境相對路徑開始計算,設定時都是以/作為開頭,如果您請求時的路徑是/pages/index.faces,則JSF會將擴展名改為/pages/index.jsp,以此作為view-id。</p>
<p>
在<navigation-rule>中的<from-view-id>是個選擇性的定義,它規定了來源頁面的條件,<navigation-case>中定義各種導覽條件,<from-outcome>定義當窗體結果符合的條件時,各自改導向哪一個目的頁面,目的頁面是在<to-view-id>中定義。</p>
<p>
您還可以在<navigation-case>中加入<from-action>,進一步規范窗體結果必須根據哪一個動作方法(action
method),當中是使用 JSF Expression Language 來設定,例如:</p>
<div class="code" style="BORDER-TOP-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-BOTTOM-STYLE: solid">
<div class="codeContent">
<pre class="code-java">....
<navigation-rule>
<from-view-id>/pages/index.jsp</from-view-id>
<navigation-<span class="code-keyword">case</span>>
<from-action>#{user.verify}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/pages/welcome.jsp</to-view-id>
</navigation-<span class="code-keyword">case</span>>
....
</navigation-rule>
....</pre>
</div>
</div>
<p>
在導航時,預設都是使用forward的方式,您可以在<navigation-case>中加入一個<redirect/>,讓JSF發出讓瀏覽器重新導向(redirect)的header,讓瀏覽器主動要求新網頁,例如:</p>
<div class="code" style="BORDER-TOP-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-BOTTOM-STYLE: solid">
<div class="codeContent">
<pre class="code-java">....
<navigation-rule>
<from-view-id>/pages/index.jsp</from-view-id>
<navigation-<span class="code-keyword">case</span>>
<from-outcome>success</from-outcome>
<to-view-id>/pages/welcome.jsp</to-view-id>
<redirect/>
</navigation-<span class="code-keyword">case</span>>
....
</navigation-rule>
....</pre>
</div>
</div>
<p>
您的來源網頁可能是某個特定模塊,例如在/admin/下的頁面,您可以在<from-view-id>中使用wildcards,也就是使用
* 字符,例如:</p>
<div class="code" style="BORDER-TOP-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-BOTTOM-STYLE: solid">
<div class="codeContent">
<pre class="code-java">....
<navigation-rule>
<from-view-id>/admin/*</from-view-id>
<navigation-<span class="code-keyword">case</span>>
<from-action>#{user.verify}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/pages/welcome.jsp</to-view-id>
</navigation-<span class="code-keyword">case</span>>
....
</navigation-rule>
....</pre>
</div>
</div>
<p>
在上面的設定中,只要來源網頁是從/admin來的,都可以開始測試接下來的<navigation-case>。</p>
<p> <from-view-id>如果沒有設定,表示來源網頁不作限制,您也可以使用 *
顯式的在定義檔中表明,例如:</p>
<div class="code" style="BORDER-TOP-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-BOTTOM-STYLE: solid">
<div class="codeContent">
<pre class="code-java">....
<navigation-rule>
<from-view-id>/*</from-view-id>
<navigation-<span class="code-keyword">case</span>>
....
</navigation-rule>
....</pre>
</div>
</div>
<p>或者是這樣:</p>
<div class="code" style="BORDER-TOP-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-BOTTOM-STYLE: solid">
<div class="codeContent">
<pre class="code-java">....
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-<span class="code-keyword">case</span>>
....
</navigation-rule>
....</pre>
</div>
</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -