对 Liferay 中不同页面上的 portlet 使用 JSR-268 IPC

发布于 2024-12-25 04:15:02 字数 437 浏览 4 评论 0原文

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

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

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

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

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.

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.

How do I do that using Liferay?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一向肩并 2025-01-01 04:15:02

您可以在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

希望有帮助

There are a few properties that you can set in portal-ext.properties. Quoting with the comments on them (as they probably state the usage better than I could do myself:

##
## 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

Hope that helps

不顾 2025-01-01 04:15:02

奥拉夫的回答给了你一个良好的开端。只需将一个名为 portal-ext.properties 的文件放入类路径中,其内容为 portlet.event.distribution=ALL。这将确保所有关心该事件的 portlet 都会收到它,即使它位于不同的页面上。

现在切换页面:我建议创建一个处理事件的界面。该接口基本上是 portlet.xml 文件的事件定义标签在代码中的表示。这还有一个优点,您只需确保您的界面和 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”。将您在“友好 URL”字段中输入的相同 URL(不带不可更改的前缀)复制到上面的 application-context.xml 代码段中。

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

@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 片段与以下内容交换即可:

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

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

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.

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

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

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
}

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>

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

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

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

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

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文