Interstage Portalworks 管理者ガイド
目次 索引 前ページ次ページ

付録F Portletの作成方法について> F.3 Portletの作成手順

F.3.4 ユーザ情報やプリファレンスを利用するPortletの作成

Portletは、あらかじめ定義されたユーザ情報を参照することができます。ユーザ情報を参照するためには、参照したいユーザ情報のキーをportlet.xmlで宣言する必要があります。以下に例を示します。

<portlet-app>
…
   <user-attribute>
      <description>名前</description>
      <name>com.fujitsu.portalworks.common_name</name>
   </user-attribute>
   <user-attribute>
       <description>電話番号</description>
       <name>user.business-info.telecom.telephone.number</name>
   </user-attribute>
…
</portlet-app>

このように宣言したキーを用いて、ユーザ情報をPortletからアクセスするには、次のように記述します。なお、ユーザ情報自体(ユーザの名前や電話番号など)は、Portal Container側が保持しているデータを参照することが想定されているため、ユーザ情報を定義する方法は、Portletの仕様では規定されていません。

MapstUserInfo = (Map) request.getAttribute(PortletRequest.USER_INFO); 
StringstrUserName; 
StringstrTelephone; 

If (stUserInfo != null) {
  strUserName  =
   (String) stUserInfo.get("com.fujitsu.portalworks.common_name");
  strTelephone =
   (String) stUserInfo.get("user.business-info.telecom.telephone.number");
}

獲得できる情報には、以下があります。

内容

キー名

名前

com.fujitsu.portalworks.common_name

ログオンID

user.name.nickName

user.name.family

user.name.given

電話番号

user.business-info.telecom.telephone.number

住所

user.business-info.postal.street

郵便番号

user.business-info.postal.postalcode

FAX

user.business-info.telecom.fax.number

利用者選択言語

com.fujitsu.portalworks.locale

メールアドレス

user.business-info.online.email

携帯電話

user.business-info.telecom.mobile.number

接続元IPアドレス

com.fujitsu.portalworks.remote_addr

接続先ホスト名

com.fujitsu.portalworks.remote_host

肩書

user.jobtitle

また、Portletは各ユーザに応じた個々のプリファレンス(設定情報)をもつことができます。各プリファレンスのデフォルト値をportlet.xmlに定義します。以下に例を示します。portlet.xmlの記述方法については、“F.4 Portlet Applicationのパッケージ方法”を参照してください。

<portlet>
…
    <portlet-preferences>
        <preference>
            <name>SleepTime</name>
            <value>100</value>
        </preference>
        <preference>
           <name>SearchEngine</name>
           <value>http://www.google.co.jp/</value>
           <value>http://www.yahoo.co.jp/</value>
           <read-only>0</read-only>
        </preference>
    </portlet-preferences>
</portlet>

プリファレンスの内容は、ActionRequest、またはRenderRequestのgetPreferencesメソッドを利用して、javax.portlet.PortletPreferencesインタフェースオブジェクトを取得し、参照することができます。また、processActionメソッドの中では、setValue、またはsetValuesメソッドを利用して値を変更することができます。ただし、read-onlyが、“0”で指定されているプリファレンスと、renderメソッドの中で参照されるすべてのプリファレンスは参照のみが可能です。Portletから参照するには、次のように記述します。

PortletPreferencesstPrefs = request.getPreferences();
String[]   strSearchEngine; 
int   nSleepTime; 

strSearchEngine = stPrefs.getValues("SearchEngine", null); 
nSleepTime      = Integer.parseInt(stPrefs.getValue("SleepTime", null));

目次 索引 前ページ次ページ

All Rights Reserved, Copyright(C) 富士通株式会社 2007