将JSR-268 IPC用于Liferay不同页面上的portlet [英] Using JSR-268 IPC for portlets on different pages in Liferay

查看:150
本文介绍了将JSR-268 IPC用于Liferay不同页面上的portlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用WebSphere Portal开发基于Portlet的应用程序,现在我将开发环境切换到Liferay. 我正在使用JSR-286引入的事件系统进行Portlet间的通信,试图避免使用所有非标准化功能,以便同时将WebSphere Portal和Liferay用作受支持的环境.

I started developing a portlet based application using WebSphere Portal and now I am switching my development environment to Liferay. I am using the event system introduced with JSR-286 for inter-portlet communication, trying to avoid all non standardized features in order to serve both WebSphere Portal and Liferay as supported environments.

如果发布portlet和接收portlet在同一页面上,那么我的事件似乎工作正常,但是我想将这些portlet放在不同的页面上.在WebSphere上,有一个接线"配置页面,可以在其中配置portlet,以将事件发送到其他页面上的特定portlet,并且有一个选项,如果触发了此类事件,则可以自动切换页面.

My events seem to work fine if the publishing portlet and the receiving portlet are on the same page, but I would like to place those portlets on different pages. On WebSphere there is a "Wiring" configuration page where portlets can be configured to send events to specific portlets on other pages and there is an option to automatically switch the page if such an event is fired.

我如何使用Liferay做到这一点?

How do I do that using Liferay?

使用:Liferay Portal社区版6.1.0 CE(Paton/Build 6100/2011年12月15日)

Using: Liferay Portal Community Edition 6.1.0 CE (Paton / Build 6100 / December 15, 2011)

推荐答案

Olaf的答案为您提供了一个良好的开端.只需将一个名为portal-ext.properties的文件放入内容为portlet.event.distribution=ALL的类路径中即可.这样可以确保所有关心事件的portlet都可以接收该事件,即使该事件在另一个页面上也是如此.

Olaf's answer gives you a good start. Just place a file called portal-ext.properties in your classpath with the content portlet.event.distribution=ALL. This will make sure that all portlets that care for the event will receive it, even if it is on a different page.

现在可以切换页面:我建议创建一个处理事件的界面.此接口基本上是代码中portlet.xml文件的event-definition-tags的表示.这还有一个好处,就是您只需要确保您的界面和portlet.xml是同步的即可.如果接口与其余的源代码不同步,则通常是编译时错误,而不是运行时错误(例如事件的错误参数类型).

Now for switching the pages: I suggest creating an interface that handles your events. This interface is basically a representation of the portlet.xml file's event-definition-tags in code. This additionally has the advantage that you just have to make sure that your interface and your portlet.xml is in sync. If the interface is not in sync with the remaining source code then this will oftentimes be a compile time error instead of a runtime error (such as wrong parameter types to an event).

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一起使用的事件:

Then you can have a simple implementation that fires your events that you can use with 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实现另一个实现,如下所示:

Then you can have another implementation for Liferay which looks like this:

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文件中按以下方式配置实现:

Now if you are using Spring IoC (which I happen to know that you do), then you can can configure the implementation as follows in your application-context.xml file:

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

以下是您获取此xml代码段的值"部分的方法:

Here is how you get the "value"-part for this xml snippet:

在事件触发后,在liferay中打开用户应重定向到的目标页面,同时以适当的权限登录并单击Manage-> page页面顶部的菜单.您可以在此处设置友好网址".将您在Friendly-URL字段中输入的相同URL(没有不可更改的前缀)复制到上面的application-context.xml代码段中.

Open the target page in liferay to which the user should be redirected after an event was fired, while beeing logged with appropriate privileges and click in the menu at the top of the page on Manage->page. There you can set a "Friendly URL". Copy the same URL you entered in the Friendly-URL field (without the unchangable prefix) into the application-context.xml snippet above.

在引发事件的类中,您可以仅允许自动连接事件接口并像这样使用它:

In your classes that fire events you can then just allow the Events-interface to be autowired and use it like this:

@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);
  }
}

如果您将应用程序部署在WebSphere Portal上,则可以简单地将上面的xml代码片段与以下内容进行交换:

If you deploy your application on WebSphere Portal, you simple exchange the xml snippet above with the following:

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

现在,您有了一个解决方案,该解决方案允许您跨页面发送JSR-286消息,同时切换页面,同时仍然能够在Liferay和WebSphere Portal上部署应用程序而无需更改代码(只是配置需要进行调整.)

Now you you have a solution that allows you to send JSR-286 messages across pages, switching the pages at the same time, while still being able to deploy you application on both Liferay and WebSphere Portal without any change in code (just configuration needs to be adapted).

这篇关于将JSR-268 IPC用于Liferay不同页面上的portlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆