ページの先頭行へ戻る
 Apcoordinatorユーザーズガイド

E.2.1 データBeanの設定

画面で使用するデータBeanはStrutsのアクションクラスで設定します。ここではuji:tableViewを使用するため、次のようなデータBeanを作成します。

package mypkg;
import com.fujitsu.uji.DataBean;
import com.fujitsu.uji.compo.*;

public class MyDataBean extends DataBean
{
  protected TableView table = new TableView();

  public MyDataBean() {
    table.addRow(new Object[]{"ハンバーガー","400円","2個"});
    table.addRow(new Object[]{"ホットドック","300円","2個"});
    table.addRow(new Object[]{"ポテト","300円","3個"});
    table.addRow(new Object[]{"コーラ","400円","4個"});
  }

  public TableView getTable() {
    return table;
  }
}

アクションクラスからデータBeanを設定する場合は、リクエストかセションのいずれかのスコープのオブジェクトとしてセットします。すなわち、javax.servlet.http.HttpServletRequest、javax.servlet.http.HttpSessionのいずれかのインタフェースのsetAttributeメソッドを使用します。

次の例では、リクエストにデータBeanを設定しています。

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
...

public class MyAction extends Action {

 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {

  MyDataBean dataBean = new MyDataBean();
request.setAttribute("myDateBean", dataBean); ... } }