Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Rama Krishna Agthu
Sharing Request Attributes from Portal to Portlets
July 24, 2012 5:13 PM
Answer

Rama Krishna Agthu

Rank: New Member

Posts: 6

Join Date: June 27, 2012

Recent Posts

Hi,

Here is my requirement:

I have developed a hook by implementing class for PostLogin event.

In the Post Login event we have some custom logic and at the end of that we wanted to set a request attribute and this request attribute is a big java object which should be available to all the portlets in the portal.

I have followed the link(http://www.liferay.com/documentation/liferay-portal/6.1/user-guide/-/ai/request), but could not able to read the request attribute that was set in the post login event.

Steps that I followed:

1) Added the entry in the portal-ext.properties as mentioned below.

request.shared.attributes=LIFERAY_SHARED_,MY_SHARED_

2) In the custom portlet's liferay-portlet.xml file, I have added the below entry

<private-request-attributes>false</private-request-attributes>

3) In the PostLogin class at the end of my logic I have the following line of code

request.setAttribute("MY_SHARED_cusobj", javaObj);

4) In the view.jsp of custom portlet I have the following line of code.

com.my.someClass someCL= (com.my.someClass) request.getAttribute("MY_SHARED_cusobj");

I am getting null object from the above call

My questions:
===========
1) Is it the right way of doing the thing? or am i missing something?

2) Does the Liferay passes/copies the request attributes to portlet requests from the portal?

3) Is there any other solutions or better way of doing this?

Please note we don't want to use the session.

Appreciate your help.

Regards,
Rama Krishna
Nishikant sapkal
RE: Sharing Request Attributes from Portal to Portlets
July 24, 2012 11:00 PM
Answer

Nishikant sapkal

Rank: Junior Member

Posts: 76

Join Date: February 15, 2010

Recent Posts

Rama Krishna Agthu:
Hi,

Here is my requirement:

I have developed a hook by implementing class for PostLogin event.

In the Post Login event we have some custom logic and at the end of that we wanted to set a request attribute and this request attribute is a big java object which should be available to all the portlets in the portal.

I have followed the link(http://www.liferay.com/documentation/liferay-portal/6.1/user-guide/-/ai/request), but could not able to read the request attribute that was set in the post login event.

Steps that I followed:

1) Added the entry in the portal-ext.properties as mentioned below.

request.shared.attributes=LIFERAY_SHARED_,MY_SHARED_

2) In the custom portlet's liferay-portlet.xml file, I have added the below entry

<private-request-attributes>false</private-request-attributes>

3) In the PostLogin class at the end of my logic I have the following line of code

request.setAttribute("MY_SHARED_cusobj", javaObj);

4) In the view.jsp of custom portlet I have the following line of code.

com.my.someClass someCL= (com.my.someClass) request.getAttribute("MY_SHARED_cusobj");

I am getting null object from the above call

My questions:
===========
1) Is it the right way of doing the thing? or am i missing something?

2) Does the Liferay passes/copies the request attributes to portlet requests from the portal?

3) Is there any other solutions or better way of doing this?

Please note we don't want to use the session.

Appreciate your help.

Regards,
Rama Krishna


Probably you are using request -
I have tried the following code and its working for me -

1} In the PostLogin class i have set the attribute in the session -

httpSession.setAttribute("LIFERAY_SHARED_globalAttribute", "contextScope"); // replace with your big java object

2} In the custom portlet view (jsp) i have retrieve the attribute value like -

<%= request.getSession().getAttribute("LIFERAY_SHARED_globalAttribute") %>

Best regards,
Nishikant Sapkal
Rama Krishna Agthu
RE: Sharing Request Attributes from Portal to Portlets
July 25, 2012 3:12 AM
Answer

Rama Krishna Agthu

Rank: New Member

Posts: 6

Join Date: June 27, 2012

Recent Posts

Hi,

Thanks a lot for your response.

The object that we want to set here is the big java object, so we don't want to overload the session with this,

This is the reason why we want to use the request object.

Any other idea/clue?

Regards,
Rama Krishna

quote=Nishikant sapkal]
Rama Krishna Agthu:
Hi,

Here is my requirement:

I have developed a hook by implementing class for PostLogin event.

In the Post Login event we have some custom logic and at the end of that we wanted to set a request attribute and this request attribute is a big java object which should be available to all the portlets in the portal.

I have followed the link(http://www.liferay.com/documentation/liferay-portal/6.1/user-guide/-/ai/request), but could not able to read the request attribute that was set in the post login event.

Steps that I followed:

1) Added the entry in the portal-ext.properties as mentioned below.

request.shared.attributes=LIFERAY_SHARED_,MY_SHARED_

2) In the custom portlet's liferay-portlet.xml file, I have added the below entry

<private-request-attributes>false</private-request-attributes>

3) In the PostLogin class at the end of my logic I have the following line of code

request.setAttribute("MY_SHARED_cusobj", javaObj);

4) In the view.jsp of custom portlet I have the following line of code.

com.my.someClass someCL= (com.my.someClass) request.getAttribute("MY_SHARED_cusobj");

I am getting null object from the above call

My questions:
===========
1) Is it the right way of doing the thing? or am i missing something?

2) Does the Liferay passes/copies the request attributes to portlet requests from the portal?

3) Is there any other solutions or better way of doing this?

Please note we don't want to use the session.

Appreciate your help.

Regards,
Rama Krishna


Probably you are using request -
I have tried the following code and its working for me -

1} In the PostLogin class i have set the attribute in the session -

httpSession.setAttribute("LIFERAY_SHARED_globalAttribute", "contextScope"); // replace with your big java object

2} In the custom portlet view (jsp) i have retrieve the attribute value like -

<%= request.getSession().getAttribute("LIFERAY_SHARED_globalAttribute") %>

Best regards,
Nishikant Sapkal