Skip to content

Instantly share code, notes, and snippets.

@noriyukitakei
Created April 16, 2018 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noriyukitakei/41318ca03da46e4347475b058d0a2d4b to your computer and use it in GitHub Desktop.
Save noriyukitakei/41318ca03da46e4347475b058d0a2d4b to your computer and use it in GitHub Desktop.
Spring Web Flowによる今どきでないWebアプリケーション開発
package com.sios.flow;
import java.util.ArrayList;
import java.util.List;
import org.springframework.binding.message.MessageContext;
import org.springframework.stereotype.Component;
import org.springframework.webflow.action.EventFactorySupport;
import org.springframework.webflow.execution.Event;
/**
* Flow定義ファイルから呼び出す検索アクションBean
* @author Noriyuki TAKEI
*/
@Component("searchAction") // searchActionという名前でDIコンテナにDIしている。Flow定義ファイルではDIされているインスタンスを呼び出すことが出来る。
public class SearchAction {
private EventFactorySupport eventFactorySupport = new EventFactorySupport();
/**
* 検索ボタンがクリックされた時のアクションを設定します。
* Spring Web Flowの決まりで、戻り値は必ずEventクラスにする必要があります。
* 引数には検索条件を格納するFormクラス、エラーメッセージなどを格納する
* MessageContextを指定します。
*
* @param searchForm
* @param messageContext
* @return
*/
public Event search(SearchForm searchForm, MessageContext messageContext) {
// Formクラスから検索条件(タイトル)を取得します。
String title = searchForm.getTitle();
// 検索処理を行います。本来であれば、ここにゴリゴリ検索処理を書くのですが、
// 今回はSpring Web Flowの解説に注力したいので、割愛します。
// 検索処理を実行したことを前提に、検索結果を2件位入れておきます。
List<Message> messages = new ArrayList<Message>();
Message message1 = new Message();
message1.setTitle("飲み会のお知らせ");
message1.setBody("明日は飲み会です");
messages.add(message1);
Message message2 = new Message();
message2.setTitle("防犯訓練のお知らせ");
message2.setBody("明後日は防犯訓練です");
messages.add(message2);
Event event = eventFactorySupport.success(this,messages);
return event;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment