Liferay设置portlet会话值

时间:2016-06-27 04:44:03

标签: session liferay portlet

我有2个portlet,一个是MVC Portlet,另一个是JSF Porlet。 我想将属性从MVC Portlet发送到另一个。

在MVC Portlet中:

@Override
    public void processAction(ActionRequest actionRequest,
            ActionResponse actionResponse) throws IOException, PortletException {


        PortletSession portletSession = actionRequest.getPortletSession();
        portletSession.setAttribute("example", "SET ATTR PROCESS ACTION",
                PortletSession.APPLICATION_SCOPE);
....

和其他JSF Portlet:

FacesContext facesContext = FacesContext.getCurrentInstance();
PortletRequest request = (PortletRequest)facesContext.getExternalContext().getRequest();
PortletSession session = request.getPortletSession(false);
String testString = (String) session.getAttribute("example",PortletSession.APPLICATION_SCOPE);

但是testString的值总是返回null。

两个portlet都在liferay-portlet.xml中配置:

Dim myText = "Howard Johnson, 21 (USA)"
Dim LastName = myText.Split(" "c, ","c)(1)  ' myText.Split(" "c, ","c) gives array {"Howard", "Johnson", "", "21", "(USA)"}

我是liferay的新人。谢谢你的帮助!

2 个答案:

答案 0 :(得分:0)

尝试添加" LIFERAY_SHARED _"在属性名称之前,即:

portletSession.setAttribute("LIFERAY_SHARED_example", "SET ATTR PROCESS ACTION", PortletSession.APPLICATION_SCOPE);

然后用同一个名字读它:

String testString = (String) session.getAttribute("LIFERAY_SHARED_example", PortletSession.APPLICATION_SCOPE);

此外,您可以通过在portal-ext.properties中指定它来更改此前缀:

session.shared.attributes=CUSTOM_PREFIX_

答案 1 :(得分:-1)

您必须在 Liferay-portlet.xml <中将属性 “private-session-attributes” 设置为false / strong>每个portlet的文件。在“<portlet>”标记中添加以下行:

<private-session-attributes>false</private-session-attributes>