Ajaxフレームワーク ユーザーズガイド
|
目次
索引

|
3.2.1 データBeanとビジネスクラスの作成
ここでは、Apcoordinator用のデータBeanとビジネスクラスの作成方法について説明します。また、作成したビジネスクラスを呼び出すために必要なコマンドマップの定義方法についても説明します。
データBeanは、Apcoordinatorアプリケーションと同様に、com.fujitsu.uji.DataBeanを継承して作成します。データBeanに利用できるプロパティの型は、データ型変換機能で対応する型です。詳細は、“データ型変換機能”を参照してください。
ApcoordinatorアプリケーションとデータBeanを共有する場合でも、データBeanの作成方法は同じです。
以下に、データBeanの記述例を示します。
package mypkg;
import com.fujitsu.uji.DataBean;
public class BodyBean extends DataBean {
protected String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
} |
ビジネスクラスは、Apcoordinatorアプリケーションと同様に、com.fujitsu.uji.GenericHandlerを継承して作成します。ただし、ビジネスメソッドの戻り値は、returnで記述します。返却されたオブジェクトは、クライアントのレスポンスハンドラに渡されます。
なお、ビジネスクラスのインスタンスのライフサイクルは、initメソッドの戻り値で決まります。
また、ビジネスクラスに渡されるDispatchContextオブジェクトの実体は、HttpDispatchContextを継承したAcfHttpDispatchContextオブジェクトです。
- データBeanを共有しない場合のビジネスクラスの記述例
- 以下に、ApcoordinatorアプリケーションとデータBeanを共有しない場合の、ビジネスクラスの記述例を示します。
package mypkg;
import com.fujitsu.uji.DispatchContext;
import com.fujitsu.uji.GenericHandler;
public class MyHandler extends GenericHandler
{
public boolean init() {
return true;
}
public Object doSomething(DispatchContext context, BodyBean dataBean) {
// 業務ロジックを記述
(省略)
// 戻り値はreturnで記述
NextBean retBean = new NextBean();
return retBean;
}
} |
- データBeanを共有する場合のビジネスクラスの記述例
- 以下に、ApcoordinatorアプリケーションとデータBeanを共有する場合の、ビジネスクラスの記述例を示します。
以下の例では、Apcoordinatorの表示画面の領域名(body)に設定されたデータBean(BodyBean)を共有します。
package mypkg;
import com.fujitsu.uji.DispatchContext;
import com.fujitsu.uji.GenericHandler;
public class MyHandler extends GenericHandler
{
public boolean init() {
return true;
}
/**
* Apcoordinatorの初期画面表示の処理
*/
public void startup(DispatchContext context) {
BodyBean dataBean = new BodyBean();
// 初期データの設定
(省略)
// 領域名(body)にデータBean(BodyBean)を設定
context.setResponseBean("body", dataBean);
}
/**
* Apcoordinator連携の処理
*/
public Object doSomething(DispatchContext context, BodyBean dataBean) {
// 業務ロジックを記述
(省略)
// 戻り値はreturnで記述
NextBean retBean = new NextBean();
return retBean;
}
} |
作成したビジネスクラスのメソッドを呼び出すために、コマンドマップを定義します。
以下に、コマンドマップの記述形式を示します。
入力のデータBeanのクラス名;コマンド=ビジネスクラス名.メソッド名 |
- 入力のデータBeanのクラス名
作成したデータBeanまたは共有するデータBeanのクラス名を設定します。
- コマンド
Apcoordinator連携機能で指定するコマンド名を設定します。
- ビジネスクラス名.メソッド名
作成したビジネスクラスのクラス名とメソッド名を設定します。
- データBeanを共有しない場合のコマンドマップの定義例
- 以下に、ApcoordinatorアプリケーションとデータBeanを共有しない場合の、コマンドマップの定義例を示します。
# commands.map
mypkg.BodyBean;execute=mypkg.MyHandler.doSomething |
- データBeanを共有する場合のコマンドマップの定義例
- 以下に、ApcoordinatorアプリケーションとデータBeanを共有する場合の、コマンドマップの定義例を示します。
# commands.map
## Apcoordinator
;=mypkg.MyHandler.startup
## Ajax
mypkg.BodyBean;execute=mypkg.MyHandler.doSomething |
Copyright 2008 FUJITSU LIMITED