多个Portlet传参与交互

多个Portlet传参与交互

portlet之间传参有4种方式:
1、application级别的PortletSession
2、JSR 286 中的共享参数
3、JSR 286 中的事件机制
4、AJAX方式

一,application级别的PortletSession

PortletSession session = request.getPortletSession();//得到session

session.setAttribute("param", "1",PortletSession.APPLICATION_SCOPE);//设置值

session.getAttribute("param",PortletSession.APPLICATION_SCOPE);//获取值

二,JSR 286 中的共享参数

如果你想在多个portlet间共享参数,一种方法就是将共享参数存放在用户的session中.Liferay Portal有一些比较好的设置来共享参数如liferay-portlet.xml 中<shared-session-attributes>和portal-ext.properties 中shared.session.attributes.

但你尝试过session-less,或者通过session让所有用户共享参数?

有一种方式是将共享参数存放在ROOT context中,第一步是在Liferay EXT 环境中创建GlobalStartupAction,如下:

package com.foo.liferay.startup;public class GlobalStartupAction extends SimpleAction { private static List<String> fooList;
public List<String> getFooList() {
return fooList;
}

public static void
@Override public void run(String[] ids) throws ActionException {
// Cache all the data
fooList = new ArrayList<String>();
fooList.add(new String("red"));
fooList.add(new String("green"));
fooList.add(new String("blue"));
}
}

GlobalStartupAction需要在portal-ext.properties配置. Liferay自身启动已经指明一个全局启动action,我们可以通过一个逗号分隔的列表,在Liferay补充的GlobalStartupAction:

global.startup.events=com.liferay.portal.events.GlobalStartupAction,com.foo.liferay.startup.GlobalStartupAction

然后在每个portlet中,使用Liferay PortalClassInvoker调用静态getFooList()方法。实用的数字PortalClassInvoker的类装载器的Liferay Portal context之前,要求在指定的方法:

import com.liferay.portal.kernel.util.PortalClassInvoker;

public class ApplicationScopeBean {

    private static final List fooList;

    public ApplicationScopeBean() {
        List<String> fooList = (List<String>) PortalClassInvoker.invoke("com.foo.liferay.startup.GlobalStartupAction", "getFooList"));

}

}

参考资料:http://www.liferay.com/web/ngriffin/blog/-/blogs/sharing-data-between-portlets

三、JSR 286 中的事件机制

1,在portlet1中添加action处理

public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws throws PortletException, IOException{
   actionResponse.setEvent("simple-event", "simple-event is sent by "
     + portletConfig.getPortletName());

}

2,jsp页面中添加form,触发portlet的action

<form method="POST" action="<portlet:actionURL/>">
          <input type="submit" value="点击产生触发事件">
</form>

3,在portlet2中添加事件处理

    public void processEvent(EventRequest eventRequest,
            EventResponse eventResponse) throws PortletException, IOException {
        Event event = eventRequest.getEvent();
        eventResponse.setRenderParameter("eventName", event.getName());
        eventResponse.setRenderParameter("eventValue", event.getValue().toString());
    }
4,jsp页面中显示事件内容

Event name:<%=renderRequest.getParameter("eventName")%>

Event value:<%=renderRequest.getParameter("eventValue")%>

5,在portlet.xml文件中添加

<event-definition>
   <name>simple-event</name>
   <value-type>java.lang.String</value-type>
</event-definition>
6,在portlet.xml文件每个portlet中添加

   <supported-processing-event>
    <name>simple-event</name>
   </supported-processing-event>

四,AJAX方式

五,URL地址传值[试验中]

http://localhost:8080/web/guest/home?p_p_id=FlashPortlet_WAR_ShowFlashportlet_INSTANCE_Qa7V&p_p_lifecycle=0&参数=值


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值