ダウンロード サンプルソース (47.4 KB)
ポートレットの開発
ポートレットを開発するには、まず標準的なJavaプロジェクトを作成します。これをポートレットプロジェクトにするには、portlet.xmlファイルを作成します。このファイルは、コンテナで使用可能なポートレットと、それらをインスタンス化するために使用するクラスを定義する、デプロイメントデスクリプタです。ただし、ポータルがポートレットを登録し認識する方法については仕様に定義されていません。
本稿のサンプルでは、Java Springフレームワークを使用しました。このフレームワークには、ポートレットAPIに対する作業を簡素化するための、便利なユーティリティやコンテナビーンが提供されています。筆者は、ポートレットプロジェクトの設定にEclipse IDEも使用しました。しかし、ポートレットをJSR 168またはJSR 286に準拠して作成すれば、これに準拠する任意のコンテナ上で動作させることができるため、本稿のサンプルのコーディングやビルドにこれと同じ技術を用いる必要はありません。
図5に、サンプルポートレットプロジェクトの構造を示します。

このサンプルプロジェクトのportlet.xmlファイルでは、次のように1つのポートレットを定義します。
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns=
"http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0">
<portlet>
<portlet-name>QuickSearch</portlet-name>
<portlet-class>
org.springframework.web.portlet.DispatcherPortlet
</portlet-class>
<init-param>
<name>contextConfigLocation</name>
<value>/WEB-INF/context/portlet/QuickSearchDefinition.xml</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>Quick Search</title>
</portlet-info>
</portlet>
</portlet-app>
上のportlet.xmlファイルでは、Springクラスの初期化パラメータとしてcontextConfigLocationを指定しています。
リスト1に、SpringのcontextConfigLocationファイルのサンプルを示します。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
<bean id="quickEntitySearchController"
class="com.portlet.controller.QuickSearchController"
parent="basePageController">
<property name="sessionForm"><value>true</value></property>
<!-- Keep command object throughout session -->
<property name="commandName" value="commandObject"/>
<property name="commandClass"
value="com.portlet.command.commandObject"/>
<property name="formView"><value>quick.search</value></property>
<property name="successView"><value>quick.search</value></property>
<property name="bindOnNewForm"><value>true</value></property>
<property name="quickServiceClient" ref="quickServiceClient"/>
</bean>
<bean id="portletModeParameterHandlerMapping" class="
org.springframework.web.portlet.handler.
PortletModeParameterHandlerMapping">
<property name="order" value="10"/>
<property name="interceptors">
<list>
<ref bean="parameterMappingInterceptor" />
</list>
</property>
<property name="portletModeParameterMap">
<map>
<entry key="view">
<map>
<entry key="basePageAction">
<ref bean="quickSearchController"/>
</entry>
</map>
</entry>
</map>
</property>
</bean>
<bean id="portletModeHandlerMapping" class=
"org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property name="interceptors">
<list>
<ref bean="parameterMappingInterceptor" />
</list>
</property>
<property name="portletModeMap">
<map>
<entry key="view"><ref bean="quickSearchController"/></entry>
</map>
</property>
</bean>
</beans>
この記事は参考になりましたか?
- japan.internet.com翻訳記事連載記事一覧
- この記事の著者
-
japan.internet.com(ジャパンインターネットコム)
japan.internet.com は、1999年9月にオープンした、日本初のネットビジネス専門ニュースサイト。月間2億以上のページビューを誇る米国 Jupitermedia Corporation (Nasdaq: JUPM) のニュースサイト internet.com や EarthWeb.com からの最新記事を日本語に翻訳して掲載するとともに、日本独自のネットビジネス関連記事やレポートを配信。
※プロフィールは、執筆時点、または直近の記事の寄稿時点での内容です
-
Vlad Kofman(Vlad Kofman)
ウォールストリート有数の企業でエンタープライズレベルのプロジェクトに携わる。また、米国政府の防衛関連の仕事も手がけている。特に関心を寄せているのは、オブジェクト指向プログラミング方法論、UI、デザインパターン。
※プロフィールは、執筆時点、または直近の記事の寄稿時点での内容です
この記事は参考になりましたか?
この記事をシェア
