PowerPoint プレゼンテーション

画面遷移
J2EE II 第8回
2004年11月11日
1
ここでの内容

JSFでの画面遷移の方法について学ぶ。
2
画面遷移とは?

画面1のボタ
ンを押したら
画面2に飛
ぶ
3
画面1のJSP
<f:view>
<h:form id="searchForm">
<p>1枚目のページだよ!
ボタンをクリックしてね。</p>
<h:commandButton id="button1"
action="success" value="Go!" />
</h:form>
</f:view>
4
h:commandButton 要素 (1)
<h:commandButton id="button1"
action="success" value="Go!" />
 ボタンを表すUIコンポーネント
 id 属性がある。
 value 属性の値は、ボタンのラベルになる。
5
h:commandButton 要素 (2)
<h:commandButton id="button1"
action="success" value="Go!" />
 action 属性の値は outcome という。
 ボタンが押されると、どこかのページに遷移する。


どのページに遷移するかという情報を得るために、
outcome を使う。
outcome・遷移元・遷移先の情報は、facesconfig.xml に記述する。
6
faces-config.xml の編集
<navigation-rule>
<from-view-id>/page1.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/page2.jsp</to-view-id>
</navigation-case>
</navigation-rule>
7
from-view-id 要素
<from-view-id>/page1.jsp</from-view-id>

遷移元になるJSP
8
navigation-case 要素
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/page2.jsp</to-view-id>
</navigation-case>

(page1.jspで) “success” という outcome が返さ
れたら、/page2.jsp に遷移する。
9
まとめ




ボタンが押されると、どこかのページに遷移する。
どのページに遷移するかという情報を得るため
に、commandButton タグの outcome を使う。
outcome・遷移元・遷移先の情報は、facesconfig.xml に記述する。
遷移元と outcome の情報により、遷移先が決
定される。
10