uCosminexus Portal Framework ポートレット開発ガイド

[目次][用語][索引][前へ][次へ]


8.7.3 ポートレットアクションモジュールの開発

ここでは,開発例の,ポートレットアクションモジュールの内容を説明します。

<この項の構成>
(1) <リンク集>ポートレットのポートレットアクションモジュール
(2) <デスクトップ>ポートレットまたは<ヘルプ>ポートレットのポートレットアクションモジュール

(1) <リンク集>ポートレットのポートレットアクションモジュール

<リンク集>ポートレットの,ポートレットアクションモジュールの内容を次に示します。

package jp.co.hitachi.soft.portal.portlet.api;
 
import javax.servlet.http.HttpServletRequest;
import jp.co.hitachi.soft.portal.api.log.PortletLog;
 
public class LinkActionModule extends DefaultActionModule {
 
  /**
   * リクエストパラメタの名称<br>
   * ・形式<br>
   * JSPで,以下の形式でリクエストパラメタを設定してください。<br>
   * &識別名ポートレット名称1=表示するJSPファイル名1+識別名ポートレット名称2=表示するJSPファイル名2<br>
   * ・例<br>
   *  &hptl.ex.comlink.url.PortletName1=a.jsp+hptl.ex.comlink.url.PortletName2=b.jsp+...
   */
  public static final String PARAM_REQUEST_LINK = "hptl.ex.comlink.url.";
 
  /**
   * ポートレット間通信イベント処理<br>
   * @param request イベント処理に渡されたリクエストオブジェクト
   */
  public void receive(HttpServletRequest request) {
    try {
      // Webブラウザからのリクエストパラメタを取得します。
      String value = request.getParameter(PARAM_REQUEST_LINK + getSrcPortletName(request));
      // サイトのエンコーディングがShift_JISの場合,次の処理を行う。
      value = new String(value.getBytes("iso-8859-1"),"Windows-31J");
      // もし,リクエストパラメタが存在していれば,メッセージを送信します。
      if (value != null) {
        // 実際にメッセージ(表示するJSPファイル名称)を送信します
        send(request, getSrcPortletName(request), value);
      }
    }catch (java.lang.Exception e) {
      // アプリケーションログにエラー情報を出力します
      getPortletLog(request, "log").error("receive error", e);
    }
  }
}

(2) <デスクトップ>ポートレットまたは<ヘルプ>ポートレットのポートレットアクションモジュール

<デスクトップ>ポートレットまたは<ヘルプ>ポートレットの,ポートレットアクションモジュールの内容を次に示します。

package jp.co.hitachi.soft.portal.portlet.api;
 
import jp.co.hitachi.soft.portal.portlet.api.*;
import javax.servlet.http.HttpServletRequest;
import jp.co.hitachi.soft.portal.portlet.beans.PortletInfoBean;
/**
* アクションイベント機能が提供するAPIです。<br>
*/
public class ViewActionModule extends DefaultActionModule {
 
  /**
   * ポートレットの定義に指定するパラメタ。<br>
   * 通知するポートレット名称を指定します。<br>
   */
  public static final String PORTLET_PARAMETER_SEND_NAME = "hptl.ex.comlink.send.name";
  /**
   * ポートレット情報取得Beanのbeanidを設定します。<br>
   */
  public static final String BEAN_ID_PORTLET_INFO = "hptl.ex.comlink.bean.ViewActionModule";
  /**
   * JSPに設定するパラメタ名称を設定します。<br>
   */
  public static final String CONTENT_PARAMETER_INCLUDE_NAME = "hptl.ex.comlink.include.name";
  /**
   * ポートレットアクションイベント処理<br>
   * @param request イベント処理に渡されたリクエストオブジェクト
   */
  public void action(HttpServletRequest request) {
    try {
      // 送信先ポートレット名称を取得する
      String portletName = getPortletInfo(request, BEAN_ID_PORTLET_INFO).
getParameter(PORTLET_PARAMETER_SEND_NAME);
      // メッセージを送信する
      send(request, portletName, null);
    }catch (java.lang.Exception e) {
      // アプリケーションログにエラー情報を出力します
      getPortletLog(request, "log").error("ViewActionModule.action error", e);
    }
  }
  /**
   * ポートレット間通信イベント処理<br>
   * @param request イベント処理に渡されたリクエストオブジェクト
   */
  public void receive(HttpServletRequest request) {
    try {
      // 送信先ポートレット名称を取得する
      String portletName = getPortletInfo(request, BEAN_ID_PORTLET_INFO).
getParameter(PORTLET_PARAMETER_SEND_NAME);
      // 送信先ポートレット名称と,受信したポートレットが一致している
      if (getSrcPortletName(request).equals(portletName)) {
        // メッセージ(JSPファイル名)を取得する
        String name = (String)getMessage(request);
        // JSP/サーブレットに対するインタフェースを設定します
        request.setAttribute(CONTENT_PARAMETER_INCLUDE_NAME, name);
      }
    }catch (java.lang.Exception e) {
      // アプリケーションログにエラー情報を出力します
      getPortletLog(request, "log").error("ViewActionModule.receive error", e);
    }
  }
}

[目次][前へ][次へ]


[他社商品名称に関する表示]

All Rights Reserved. Copyright (C) 2009, 2013, Hitachi, Ltd.
All Rights Reserved. Copyright (C) 2009, 2013, Hitachi INS Software, Ltd.