0

WebSphere Portalを使用してポートレットベースのアプリケーションの開発を開始し、現在、開発環境をLiferayに切り替えています。ポートレット間通信にJSR-286で導入されたイベント・システムを使用しており、WebSphere PortalとLiferayの両方をサポートされる環境として提供するために、標準化されていないすべての機能を回避しようとしています。

公開ポートレットと受信ポートレットが同じページにある場合、イベントは正常に機能しているように見えますが、これらのポートレットを別のページに配置したいと思います。WebSphereには、他のページの特定のポートレットにイベントを送信するようにポートレットを構成できる「配線」構成ページがあり、そのようなイベントが発生した場合にページを自動的に切り替えるオプションがあります。

Liferayを使用してそれを行うにはどうすればよいですか?

使用:Liferay Portal Community Edition 6.1.0 CE(Paton / Build 6100 / 2011年12月15日)

4

2 に答える 2

2

portal-ext.propertiesで設定できるプロパティがいくつかあります。それらについてのコメントで引用します(彼らはおそらく私が自分でできるよりも良い使用法を述べているので:

##
## Portlet Coordination
##

#
# Set this property to specify how events are distributed. If the value is
# "layout-set", then events will be distributed to all portlets contained in
# a layout set. If the value is "layout", then events will be distributed to
# all portlets that are present in a layout.
#
portlet.event.distribution=layout

#
# Set this property to specify how public render parameters are distributed.
# If the value is "layout-set", then public render parameters will be
# distributed to all portlets contained in a layout set. This will only work
# correctly if the property "layout.default.p_l_reset" is set to false. If
# the value is "layout", then public render parameters will be distributed
# to all portlets that are present in a layout.
#
portlet.public.render.parameter.distribution=layout

.....

#
# Set the default value for the "p_l_reset" parameter. If set to true, then
# render parameters are cleared when different pages are hit. This is not
# the behavior promoted by the portlet specification, but is the one that
# most end users seem to prefer.
#
layout.default.p_l_reset=true

お役に立てば幸い

于 2012-01-05T23:05:00.907 に答える
1

オラフの答えはあなたに良いスタートを与えます。portal-ext.propertiesクラスパスに呼び出されたファイルをコンテンツとともに配置するだけportlet.event.distribution=ALLです。これにより、イベントが別のページにある場合でも、イベントを処理するすべてのポートレットがイベントを確実に受信できるようになります。

ページを切り替えるために:イベントを処理するインターフェースを作成することをお勧めします。このインターフェースは基本的に、portlet.xmlファイルのevent-definition-tagsをコードで表現したものです。これには、インターフェースとportlet.xmlが同期していることを確認するだけでよいという利点もあります。インターフェイスが残りのソースコードと同期していない場合、これは多くの場合、ランタイムエラー(イベントへの誤ったパラメータタイプなど)ではなく、コンパイル時エラーになります。

interface Events
{
  public static final String EVENT_NAME_X ="eventX"; // as defined in portlet.xml
  public static final String EVENT_NAME_Y ="eventY";
  public void fireEventX(ActionResponse response, ParamType param);
  public void fireEventY(ActionResponse response, ParamType param);
}

次に、WebSphereで使用できるイベントを発生させる簡単な実装を作成できます。

public class SimpleEvents implements Events
{
    @Override
    public void fireEventX(ActionResponse response, ParamType param)
    {
        response.setEvent(EVENT_NAME_X, param);
    }

    @Override
    public void fireEventY(ActionResponse response, ParamType param)
    {
        response.setEvent(EVENT_NAME_Y, param);
    }
}

次に、次のようなLiferayの別の実装を作成できます。

public class RedirectingEvents extends SimpleEvents
{
  private String eventXRedirect;
  private String eventYRedirect;

    @Override
    public void fireEventX(ActionResponse response, ParamType param)
    {
        super.fireEventX(param);
        if (eventXRedirect != null)
          response.sendRedirect(eventXRedirect);
    }

    @Override
    public void fireEventY(ActionResponse response, ParamType param)
    {
        super.fireEventY(param);
        if (eventXRedirect != null)
          response.sendRedirect(eventYRedirect);
    }
    // setters & getters
}

これで、Spring IoCを使用している場合(私はあなたが使用していることを知っています)、application-context.xmlファイルで次のように実装を構成できます。

<bean class="package.RedirectingEvents" primary="true">
  <property name="eventXRedirect" value="/page-after-X-event" />
  <property name="eventYRedirect" value="/page-after-Y-event" />
</bean>

このxmlスニペットの「値」部分を取得する方法は次のとおりです。

イベントが発生した後にユーザーがリダイレクトされるターゲットページをliferayで開き、適切な権限でログに記録し、ページ上部の[管理]->[ページ]のメニューをクリックします。そこで、「フレンドリURL」を設定できます。Friendly-URLフィールドに入力したものと同じURL(変更できないプレフィックスなし)を上記のapplication-context.xmlスニペットにコピーします。

イベントを発生させるクラスでは、Events-interfaceを自動配線して、次のように使用できます。

@Controller
class Foobar
{
  @Autowired
  private Events portletEvents;
  @ActionMapping
  public void action(ActionRequest request, ActionResponse response)
  {
    portletEvents.fireEventX(someParam);
  }
  @EventMapping(Events.EVENT_NAME_Y)
  public void handleEventRequest(EventRequest request, EventResponse response)
  {
    Object value = request.getEvent().getValue();
    log.info("got Y event! Value is: " + value);
  }
}

アプリケーションをWebSpherePortalにデプロイする場合は、上記のxmlスニペットを以下と単純に交換します。

<bean class="package.SimpleEvents" primary="true" />

これで、JSR-286メッセージをページ間で送信し、同時にページを切り替えることができるソリューションができました。コードを変更することなく、LiferayとWebSphere Portalの両方にアプリケーションをデプロイできます(構成のみが必要です)。適応する)。

于 2012-01-09T16:58:02.723 に答える