Strutsのアクションとビューの構成には大きく3パターンありますが、少しずつ書いていこうと思います。3パターンとは、
- 更新系
- 表示・検索系
- ビューを伴わない系(ダウンロード、AjaxでのJSONレスポンス等)
というようなパターンです。
まずは更新系の一覧画面から新規登録を行うケースで、一覧画面から、入力画面、確認画面、完了画面と遷移するパターンです。
ビュー(画面)ですが、以下の構成になります。
入力画面
<html:form action="入力アクション">
<html:cancel>戻る</html:cancel>
<html:submit>確認</html:submit>
確認画面
<html:form action="登録アクション">
<html:cancel>戻る</html:cancel>
<html:submit>登録</html:submit>
完了画面
フォームなし
そしてアクションの定義が以下のようになります。
<action type="初期表示アクション">
<forward path="入力画面" name="成功"/>
</action>
<action type="入力アクション">
<forward path="確認画面" name="成功"/>
<forward path="入力画面" name="失敗"/>
<forward path="一覧画面" name="戻る" redirect="true"/>
</action>
<action type="登録アクション">
<forward path="入力画面" name="戻る"/>
<forward path="入力画面" name="失敗"/>
<forward path="完了アクション" name="成功" redirect="true"/>
</action>
<action type="完了アクション">
<forward path="完了画面" name="成功"/>
</action>
F5キー対策のために登録後はリダイレクトを行っています。