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

对Liferay中不同页面上的Portlet使用JSR-268 IPC,liferay,portlet,jsr286,Liferay,Portlet,Jsr286,我开始使用WebSpherePortal开发基于portlet的应用程序,现在我将开发环境切换到Liferay。 我使用JSR-286引入的事件系统进行portlet间通信,试图避免所有非标准化特性,以便将WebSpherePortal和Liferay作为受支持的环境 如果发布portlet和接收portlet位于同一页面上,我的事件似乎可以正常工作,但我希望将这些portlet放在不同的页面上。在WebSphere上有一个“连接”配置页面,其中Portlet可以配置为向其他页面上的特定Port

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

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

我如何使用Liferay做到这一点


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

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

希望对您有所帮助

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

希望这对您有所帮助

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

现在切换页面:我建议创建一个处理事件的接口。该接口基本上是portlet.xml文件的事件定义标记在代码中的表示。另外,这还有一个优点,即您只需确保您的接口和portlet.xml同步。如果接口与剩下的源代码通常是编译时错误,而不是运行时错误(例如错误的事件参数类型)

接口事件
{
公共静态最终字符串EVENT\u NAME\u X=“eventX”//如portlet.xml中所定义
公共静态最终字符串事件\u NAME\u Y=“eventY”;
public void fireventx(ActionResponse-response,ParamType-param);
public void fireventy(ActionResponse-response,ParamType-param);
}
然后,您可以使用一个简单的实现来触发您可以与WebSphere一起使用的事件:

公共类SimpleEvents实现事件
{
@凌驾
public void fireventx(ActionResponse响应,ParamType param)
{
response.setEvent(事件名称,参数);
}
@凌驾
public void fireventy(ActionResponse响应,ParamType param)
{
response.setEvent(事件名称,参数);
}
}
然后,您可以使用另一个Liferay实现,如下所示:

公共类重定向事件扩展了SimpleEvents
{
私有字符串eventXRedirect;
私有字符串eventYRedirect;
@凌驾
public void fireventx(ActionResponse响应,ParamType param)
{
super.fireventx(param);
if(eventXRedirect!=null)
sendRedirect(eventXRedirect);
}
@凌驾
public void fireventy(ActionResponse响应,ParamType param)
{
超级fireEventY(param);
if(eventXRedirect!=null)
sendRedirect(eventYRedirect);
}
//二传手和接球手
}
现在,如果您正在使用Spring IoC(我碰巧知道您是这样做的),那么您可以在application-context.xml文件中按如下方式配置实现:


以下是如何获取此xml片段的“值”部分:

在liferay中打开目标页面,用户在触发事件后应重定向到该页面,同时以适当的权限登录,然后单击页面顶部的菜单中的管理->页面。在该页面中,您可以设置“友好URL”。复制您在友好URL字段中输入的相同URL(不带不可更改的前缀)进入上面的application-context.xml代码段

在触发事件的类中,您可以只允许事件接口自动连接并按如下方式使用:

@控制器
福巴级
{
@自动连线
私人事件;
@动作映射
公共无效操作(ActionRequest请求、ActionResponse响应)
{
fireventx(someParam);
}
@事件映射(Events.EVENT\u NAME\u Y)
public void handleEventRequest(EventRequest请求、EventResponse响应)
{
对象值=request.getEvent().getValue();
log.info(“获得Y事件!值为:”+Value);
}
}
如果在WebSphere Portal上部署应用程序,则可以使用以下内容简单地交换上面的xml片段:



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

Olaf的回答给了您一个好的开始。只需在类路径中放置一个名为
portal-ext.properties
的文件,其中包含内容
portlet.event.distribution=ALL
。这将确保所有关心事件的portlet都将收到它,即使它位于不同的页面上

现在切换页面:我建议创建一个处理事件的接口。该接口基本上是portlet.xml文件的事件定义标记在代码中的表示。另外,这还有一个优点,即您只需确保您的接口和portlet.xml同步。如果接口与剩下的源代码通常是编译时错误,而不是运行时错误(例如错误的事件参数类型)