Le Nam
Le Nam

Reputation: 11

Liferay set portlet Session value

I have 2 portlet, one is MVC Portlet and another is JSF Porlet. i want to send Attribute from MVC Portlet to another.

in 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);
....

and in other 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);

But the value of testString always return null.

Both of 2 portlet have config in liferay-portlet.xml:

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

I am new with liferay. Thanks for help!

Upvotes: 0

Views: 3299

Answers (2)

Radouane ROUFID
Radouane ROUFID

Reputation: 10813

You have to set the property “private-session-attributes” to false in the Liferay-portlet.xml file of each portlet. Add the following line within the “<portlet>” tag :

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

Upvotes: -1

mdziob
mdziob

Reputation: 1166

Try to add "LIFERAY_SHARED_" before attribute name, i.e.:

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

And then read it by the same name:

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

Also, you can change this prefix by specifying it in portal-ext.properties:

session.shared.attributes=CUSTOM_PREFIX_

Upvotes: 0

Related Questions