ターゲット・ポートレット・クラスのコードが必ず次の要件を満たしていることを確認する。 - アクションは、ポートレット・アクション、Faces アクション、
または Struts アクションのいずれかとして実装する必要があります。ポートレット・アクションの場合は、使用すべきではない
PortletAction クラスではなく、単純なアクション Strings を使用する必要があります。
- ポートレット・アクションは単一のパラメーターを受け入れる必要があります。パラメーターは、アクション宣言または登録での指定に応じて、
要求パラメーター、要求属性、セッション属性、
または action 属性 (使用すべきではない) として表示されることがあります。
次の例は、サンプル素材集からの「連携ポートレット」アプリケーション・サンプル内の
OrderDetailPortlet.java の actionPerformed() メソッドを示します。
このポートレットは、その actionPerformed() メソッド内の ORDER_ID パラメーターを受け入れます。
このパラメーターは、ポートレットの WSDL ファイル (この例では OrderDetailC2A.wsdl) のバインディング・セクション内の入力パラメーターに対応します。
...
private static final String PREFIX = "";
public static final String ORDER_ID = PREFIX + "orderId";
public static final String TRACKING_ID = PREFIX + "trackingId";
...
public void actionPerformed (ActionEvent event)
{
// DefaultPortletAction action = (DefaultPortletAction) event.getAction();
String actionName = event.getActionString();
PortletRequest request = event.getRequest();
//An action causes the state to be modified
ShippingUtils.setLastModified(request);
if( getPortletLog().isDebugEnabled() ) {
getPortletLog().debug("OrderDetailActionListener - Action called");
}
if (actionName.equals(ORDER_DETAILS)) {
request.getPortletSession().setAttribute(ACTION_NAME, ORDER_DETAILS);
request.getPortletSession().setAttribute(ORDER_ID, request.getParameter(ORDER_ID));
//We do this as tracking id is an out param in the C2A WSDL file
//We write the tracking id in the request so it can be published by
//the broker in the same event cycle
String orderId = (String) request.getPortletSession().getAttribute(ORDER_ID);
OrderDetail od = ShippingDB.getOrderDetail(request.getParameter(ORDER_ID));
request.getPortletSession().setAttribute(ORDER_DETAIL, od);
request.setAttribute(TRACKING_ID, od.getTrackingId());
} else if (actionName.equals(ORDER_ID_ENTRY)) {
request.getPortletSession().setAttribute(ACTION_NAME, ORDER_ID_ENTRY);
}
}
...