Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
neelam bhandari
Sharing request attributes
November 28, 2011 3:31 AM
Answer

neelam bhandari

Rank: Regular Member

Posts: 102

Join Date: August 16, 2011

Recent Posts

Hi
Is it possible to share request attributes between two portlets in two different wars in liferay?

Neelam Bhandari
Rahul Pande
RE: Sharing request attributes
November 28, 2011 3:40 AM
Answer

Rahul Pande

Rank: Regular Member

Posts: 220

Join Date: July 6, 2010

Recent Posts

Hi Neelam,

If you want to share anything between two portlets then you can set following property to false in portlet.xml of both the portlets.

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

For more information please refer THIS link.

Thanks
Rahul.
neelam bhandari
RE: Sharing request attributes
November 28, 2011 3:46 AM
Answer

neelam bhandari

Rank: Regular Member

Posts: 102

Join Date: August 16, 2011

Recent Posts

Hi Rahul,
I have already added this line in my liferay-portlet.xml and also this line <private-request-attributes>false</private-request-attributes>. But still I am unable to share attributes using request.
Many thanks
Neelam
Dhrutika Vyas
RE: Sharing request attributes
November 28, 2011 4:06 AM
Answer

Dhrutika Vyas

Rank: Expert

Posts: 435

Join Date: February 9, 2009

Recent Posts

Hi ,

There is one property in portal.properties.
#
# Portlets that have been configured to use private request attributes in
# liferay-portlet.xml may still want to share some request attributes. This
# property allows you to configure which request attributes will be shared.
# Set a comma delimited list of attribute names that will be shared when the
# attribute name starts with one of the specified attribute names. For
# example, if you set the value to "hello_,world_", then all attribute names
# that start with "hello_" or "world_" will be shared.
#
request.shared.attributes=LIFERAY_SHARED_

and another way is set <private-request-attribute> to false in liferay-portlet.xml.

<!--
Set the private-request-attributes value to true if the portlet does not share
request attributes with the portal or any other portlet. The default value is
true. The property "request.shared.attributes" in portal.properties specifies
which request attributes are shared even when the private-request-attributes
value is true.
-->
<!ELEMENT private-request-attributes (#PCDATA)>

Try out both approach.

Regards,
Dhrutika
neelam bhandari
RE: Sharing request attributes
November 28, 2011 4:29 AM
Answer

neelam bhandari

Rank: Regular Member

Posts: 102

Join Date: August 16, 2011

Recent Posts

Hi Dhrutika,
I have set request.shared.attributes=LIFERAY_REQUEST_ in my portal-ext.properties file and also in my portlet i have added <private-request-attributes>false</private-request-attributes> in liferay-portlet.xml.


still request attribute is null.

Thanks for your reply
Neelam
Samir Gami
RE: Sharing request attributes
November 28, 2011 5:42 AM
Answer

Samir Gami

Rank: Regular Member

Posts: 159

Join Date: February 3, 2011

Recent Posts

neelam bhandari:

I have set request.shared.attributes=LIFERAY_REQUEST_ in my portal-ext.properties file and also in my portlet i have added <private-request-attributes>false</private-request-attributes> in liferay-portlet.xml.


Neelam,
"LIFERAY_SHARED_" is the prefix of the attribute name that you want to share across the war, like,
1
2// Set the attribute
3portletSession.setSetAttribute(LIFERAY_SHARED_ParamName , Value,PorletSession.APPLICATION_SCOPE)
4//And to retrieve value
5PortletSession.getAttribute(LIFERAY_SHARES_ParamName,PortletSession.APPLICATION_SCOPE)


if you set the request.shared.attributes=LIFERAY_REQUEST_ in portal-ext.properties then use the LIFERAY_REQUEST_ as prefix.
neelam bhandari
RE: Sharing request attributes
November 28, 2011 5:45 AM
Answer

neelam bhandari

Rank: Regular Member

Posts: 102

Join Date: August 16, 2011

Recent Posts

Hi Samir,
I am using this request.setAttribute("LIFERAY_REQUEST_URL", redirectURL.toString()); to set the request attribute in the action class of one portlet and in the render class of another portlet i used this line to access the attribute.
System.out.println("request attribute recieved is ****" + request.getAttribute("LIFERAY_REQUEST_URL"));

Many thanks
Neelam
Samir Gami
RE: Sharing request attributes
November 28, 2011 5:49 AM
Answer

Samir Gami

Rank: Regular Member

Posts: 159

Join Date: February 3, 2011

Recent Posts

neelam bhandari:
Hi Samir,
I am using this request.setAttribute("LIFERAY_REQUEST_URL", redirectURL.toString()); to set the request attribute in the action class of one portlet and in the render class of another portlet i used this line to access the attribute.
System.out.println("request attribute recieved is ****" + request.getAttribute("LIFERAY_REQUEST_URL"));

Many thanks
Neelam


its session scope not a request
You have to set those attribute into the portletSession.

This will explain parameter sharing in more detail.
neelam bhandari
RE: Sharing request attributes
November 28, 2011 6:28 AM
Answer

neelam bhandari

Rank: Regular Member

Posts: 102

Join Date: August 16, 2011

Recent Posts

Hi Samir,
I cannot use session attribute because session causes problem when user opens portal in two tabs, as tabs share the session. I want to share the request attributes between breadcrumb portlet and my custom portlet.

Thanks
Neelam
Gianluca Pindinelli
RE: Sharing request attributes
December 23, 2011 2:28 AM
Answer

Gianluca Pindinelli

Rank: Junior Member

Posts: 29

Join Date: March 17, 2010

Recent Posts

neelam bhandari:
Hi Samir,
I cannot use session attribute because session causes problem when user opens portal in two tabs, as tabs share the session. I want to share the request attributes between breadcrumb portlet and my custom portlet.

Thanks
Neelam


Hi,
I have the same problem: I MUST to use request for share my attributes but is always NULL...
I've tried all solution (LIFERAY_SHARED_, private-request-attributes properties) but nothing!!!
Now the problem is bypassed using query string url (passing parameter by query string) but I'm searching a better solution (especially for share objects between portlets).

I'm using LF 6.0.5 with JBoss 5.1, portlets using Apache Struts framework (org.apache.portals.bridges.struts.StrutsPortlet).

Thanks in advance.
neelam bhandari
RE: Sharing request attributes
December 23, 2011 3:13 AM
Answer

neelam bhandari

Rank: Regular Member

Posts: 102

Join Date: August 16, 2011

Recent Posts

Hey Gianluca ,
I was successful in sharing attributes using request.

1) In the liferay-portlet.xml for each WAR, set the following parameter to true for all portlets that should be able to share namespaced request attributes (it defaults to true):

<private-request-attributes>true</private-request-attributes>
2) In portal-ext.properties, override the following property and supply a comma-delimited list of values to use for namespacing attributes that should be shared by all portlets:

request.shared.attributes=LIFERAY_SHARED_
3) In your Action classes or JSPs, use code similar to the following to set attributes in the request that you want to be shared among all portlets:

request.setAttribute("LIFERAY_SHARED_id", "1234567890");
4) In your Action classes or JSPs, use code similar to the following to retrieve attributes from the request that have been set by another portlet:

String id = (String)request.getAttribute("LIFERAY_SHARED_id");


I am sure you must have already done so .But after implementing these changes don't forget to remove your portlets and then add them again on the pages.

events again is a better mechanism to transfer objects between two portlets in two different wars.
hope it works.
Gianluca Pindinelli
RE: Sharing request attributes
December 23, 2011 3:59 AM
Answer

Gianluca Pindinelli

Rank: Junior Member

Posts: 29

Join Date: March 17, 2010

Recent Posts

neelam bhandari:
Hey Gianluca ,
I was successful in sharing attributes using request.

1) In the liferay-portlet.xml for each WAR, set the following parameter to true for all portlets that should be able to share namespaced request attributes (it defaults to true):

<private-request-attributes>true</private-request-attributes>
2) In portal-ext.properties, override the following property and supply a comma-delimited list of values to use for namespacing attributes that should be shared by all portlets:

request.shared.attributes=LIFERAY_SHARED_
3) In your Action classes or JSPs, use code similar to the following to set attributes in the request that you want to be shared among all portlets:

request.setAttribute("LIFERAY_SHARED_id", "1234567890");
4) In your Action classes or JSPs, use code similar to the following to retrieve attributes from the request that have been set by another portlet:

String id = (String)request.getAttribute("LIFERAY_SHARED_id");


I am sure you must have already done so .But after implementing these changes don't forget to remove your portlets and then add them again on the pages.

events again is a better mechanism to transfer objects between two portlets in two different wars.
hope it works.


Hi Neelam,
thanks for you response but nothing to do...every attributes are null (I removed and added the portlets into pages but nothing change).
Regards.
sravan kumar
RE: Sharing request attributes
February 10, 2014 12:45 AM
Answer

sravan kumar

Rank: Junior Member

Posts: 74

Join Date: February 19, 2013

Recent Posts

Hi,

I think you can it on HTTPRequest instead of storing in PortletRequest