2013-11-21 42 views
0

我正在使用Spring-MVC和Liferay,并且需要通过会话将属性从一个Portlet传递到另一个Portlet。通过会话将属性从一个Portlet传递到另一个Portlet

我需要用HttpSession而不是PortletSession,或者是APPLICATION_SCOPE设置足够吗?

我需要做两件事情

  • 参数设为共享/应用程序会话

  • 从会话阅读并使用它传递给视图春Model

我想要做这样的第一个:

PortletSession session = request.getPortletSession(); 
session.setAttribute("foo", request.getParameter("foo"), 
    PortletSession.APPLICATION_SCOPE); 
response.sendRedirect("/somewhere"); 

然后第二是这样的:

@RequestMapping 
public String view(PortletSession session, Model model){ 
    if (session.getAttribute("foo") != null) { 
     model.addAttribute("foo", session.getAttribute("foo").toString()); 
    } 
return "somewhere/view"; 
} 

然后我尝试通过简单地利用${foo}在我的JSP来显示它,但没有显示出来。

请问您可以分享任何建议吗?

回答

1

我试图以不好的方式从会话中获取属性。我需要指定范围,同时从PortletSession中检索属性。

它更改为

@RequestMapping 
public String view(RenderRequest request, Model model){ 
    PortletSession session = request.getPortletSession(); 
    if (session.getAttribute("foo", 
      PortletSession.APPLICATION_SCOPE) != null) { 
     model.addAttribute("foo", session.getAttribute("foo", 
      PortletSession.APPLICATION_SCOPE).toString()); 
    } 
    return "somewhere/view"; 
} 

固定的问题。

而且有必要两个portlet这样的模块中设置专用会话属性设置为false liferay-portlet.xml

<portlet> 
    <!-- ..some previous settings and then --> 
    <private-session-attributes>false</private-session-attributes> 
</portlet> 

文件:http://www.liferay.com/community/wiki/-/wiki/Main/Portlet+to+Portlet+Communication

相关问题