0

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

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

我如何使用 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只需在您的类路径中放置一个名为content 的文件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”。将您在 Friendly-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 上部署您的应用程序,而无需更改任何代码(只需配置适应)。

于 2012-01-09T16:58:02.723 回答