目次 > 第2章 Server(Web)版チュートリアル > 2.5 画面分岐 > 2.5.1 画面分岐の設定
2.5.1 画面分岐の設定
画面の押下するボタンにより、画面を分岐したい場合はServer(Web)版が提供するDispatchActionを利用する。
Strutsが提供しているDispatcherActionとは異なり、リクエストパラメータの値を用いて、遷移先が決定される。
以下にアクションマッピング図を示す。
■ アクションマッピング図
手順
本項では以下の手順が必要になる。
(1) 遷移先画面の作成
メニュー画面からの遷移先である、「登録画面」と「一覧表示画面」を作成する。
本節ではタイトル画面のみ表示する。
- “terasoluna-spring-thin-blank\webapps”に“userManager”フォルダを作成する。
- 1で作成したuserManagerフォルダ内に「登録画面」の“insert.jsp”と「一覧表示画面」“list.jsp”を作成し、以下のように編集する。
- “insert.jsp”の編集内容
<%@ page contentType="text/html; charset=Windows-31J"%> <%@ taglib uri="/struts-html" prefix="html" %> <%@ taglib uri="/struts-bean" prefix="bean" %> <%@ taglib uri="/struts-logic" prefix="logic" %> <%@ taglib uri="/terasoluna-struts" prefix="ts" %> <%@ taglib uri="/terasoluna" prefix="t" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html:html> <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis"> <title>登録画面</title> </head> <body> <table border="0" style="width:100%;"> <tr> <td align="center"> <html:img module="/" page="/image/terasoluna_logo.gif" /> </td> </tr> <tr> <td align="center"> <h2> 登録画面 </h2> </td> </tr> </table> <hr> <ts:link page="/logon/menuSCR.do">メニュー</ts:link> </body> </html:html>
- “list.jsp”の編集内容
<%@ page contentType="text/html; charset=Windows-31J"%> <%@ taglib uri="/struts-html" prefix="html" %> <%@ taglib uri="/struts-bean" prefix="bean" %> <%@ taglib uri="/struts-logic" prefix="logic" %> <%@ taglib uri="/terasoluna-struts" prefix="ts" %> <%@ taglib uri="/terasoluna" prefix="t" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html:html> <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis"> <title>一覧表示画面</title> </head> <body> <table border="0" style="width:100%;"> <tr> <td align="center"> <html:img module="/" page="/image/terasoluna_logo.gif" /> </td> </tr> <tr> <td align="center"> <h2> 一覧表示画面 </h2> </td> </tr> </table> <hr> <ts:link page="/logon/menuSCR.do">メニュー</ts:link> </body> </html:html>
(2) メニュー画面の編集
メニュー画面に、「登録画面」ボタンおよび「一覧画面」ボタンとフォームの設定を追加する。
- “terasoluna-spring-thin-blank\webapps\logon\menu.jsp”を開き、以下のように編集する。
<%@ page contentType="text/html; charset=Windows-31J"%> <%@ taglib uri="/struts-html" prefix="html" %> <%@ taglib uri="/struts-bean" prefix="bean" %> <%@ taglib uri="/struts-logic" prefix="logic" %> <%@ taglib uri="/terasoluna-struts" prefix="ts" %> <%@ taglib uri="/terasoluna" prefix="t" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html:html> <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis"> <title>メニュー画面</title> </head> <body> <table border="0" style="width:100%;"> <tr> <td align="center"> <html:img module="/" page="/image/terasoluna_logo.gif" /> </td> </tr> <tr> <td align="center"> <h2> メニュー画面 </h2> ようこそ <bean:write name="USER_VALUE_OBJECT" property="userId" scope="session" ignore="true"/> さん。 </td> </tr> </table> <!-- ここから追加 --> <ts:form action="/logon/menuDSP"> <table border="0"> <tr> <td> <ts:submit value="登録画面" property="forward_insert" /> </td> </tr> <tr> <td> <ts:submit value="一覧画面" property="forward_list" /> </td> </tr> </table> </ts:form> <!-- ここまで --> <hr> <ts:link action="/logon/logoff.do" >ログオフ</ts:link> </body> </html:html>
Server(Web)版が提供するDispatchActionを利用する場合、<ts:submit>タグのproperty属性は必ず“forward_”から開始すること。
(3) Struts設定ファイルの編集
DispatchActionのアクションパスと、「登録画面」および「一覧表示画面」を表示するアクションパスを設定する。
- “terasoluna-spring-thin-blank\webapps\WEB-INF\logon\struts-logon-config.xml”を開き、以下のように追加する。
<!-- ======================================== アクションマッピング定義 --> <action-mappings type="jp.terasoluna.fw.web.struts.action.ActionMappingEx"> ・・・略・・・ <!-- メニュー画面分岐用アクション --> <action path="/logon/menuDSP" name="_logonForm" scope="session"> <forward name="insert" path="/userManager/insertSCR.do" /> <forward name="list" path="/userManager/listSCR.do" /> </action> </action-mappings>
- DispatchActionを利用する場合、<forward>タグのname属性には、<ts:submit>タグのproperty属性の“forward_”を除いた部分を指定する。
- DispatchActionを利用する場合、<forward>タグのname属性には、<ts:submit>タグのproperty属性の“forward_”を除いた部分を指定する。
- “terasoluna-spring-thin-blank\webapps\WEB-INF\userManager\struts-userManager-config.xml”を開き、以下のようにアクションパスの設定を追加する。
<!-- ======================================== アクションマッピング定義 --> <action-mappings type="jp.terasoluna.fw.web.struts.action.ActionMappingEx"> <!-- 登録画面表示用アクション --> <action path="/userManager/insertSCR" parameter="/userManager/insert.jsp"/> <!-- 一覧画面表示用アクション --> <action path="/userManager/listSCR" parameter="/userManager/list.jsp" /> </action-mappings>
(4) Spring設定ファイルの編集
DispatchActionと「登録画面」および「一覧表示画面」を表示するアクションを設定する。
- “terasoluna-spring-thin-blank\webapps\WEB-INF\logon\logonContext.xml”を開き、以下の箇所にActionクラスを設定する。
<!-- アクション定義 --> ・・・略・・・ <!-- メニュー画面分岐用アクション定義 --> <bean name="/logon/menuDSP" scope="singleton" class="jp.terasoluna.fw.web.struts.actions.DispatchAction" />
- “terasoluna-spring-thin-blank\webapps\WEB-INF\userManager\userManagerContext.xml”を開き、以下の箇所にActionクラスを設定する。
<!-- アクション定義 --> <!-- 登録画面表示用アクション定義 --> <bean name="/userManager/insertSCR" scope="singleton" class="jp.terasoluna.fw.web.struts.actions.ForwardAction" /> <!-- 一覧画面表示用アクション定義 --> <bean name="/userManager/listSCR" scope="singleton" class="jp.terasoluna.fw.web.struts.actions.ForwardAction" />