Foros de discusión

object sharing between hook and portlet

AMIT KUMAR SINGH, modificado hace 12 años.

object sharing between hook and portlet

New Member Mensajes: 10 Fecha de incorporación: 28/03/12 Mensajes recientes
Hi,

I have created a hook, which instantiates a session object to communicate with an external service. I need to share this session object with another portlet.
This will allow the portlet to use that session object to access some xml files from the remote service.

I needed the external service session object to be created in the hook because I needed the user-id and password from liferay.
I don't want to enable password saving feature so I have to use the pre login hook. My hook implements Authenticator.

Is there any way to do this?

Thanks,
Amit
thumbnail
Rahul Pande, modificado hace 12 años.

RE: object sharing between hook and portlet

Expert Mensajes: 310 Fecha de incorporación: 7/07/10 Mensajes recientes
I need to share this session object with another portlet.


As per my understanding you want to set session object from hook and use that object in portlet.

You can set the session object in http session and access that object using following code.

request.getPortletSession().getAttribute("Your Attribute Name", PortletSession.APPLICATION_SCOPE);

Here request can either render request or action request.

Thanks
Rahul
AMIT KUMAR SINGH, modificado hace 12 años.

RE: object sharing between hook and portlet

New Member Mensajes: 10 Fecha de incorporación: 28/03/12 Mensajes recientes
Thanks for the prompt response!
I probably get this wrong but
You only have access to HttpServletRequest/RenderRequest from you Action interface run call and from them all you can get is HttpSession object. I didn't understand how would you call getPortletSession()??
thumbnail
Rahul Pande, modificado hace 12 años.

RE: object sharing between hook and portlet

Expert Mensajes: 310 Fecha de incorporación: 7/07/10 Mensajes recientes
AMIT KUMAR SINGH:
You only have access to HttpServletRequest/RenderRequest from you Action interface run call and from them all you can get is HttpSession object. I didn't understand how would you call getPortletSession()??


Can you please explain it clearly. I am not able to understand what you want to say emoticon
thumbnail
Jitendra Rajput, modificado hace 12 años.

RE: object sharing between hook and portlet

Liferay Master Mensajes: 875 Fecha de incorporación: 7/01/11 Mensajes recientes
set parameter from hook ..

HttpSession session = request.getSession(false);  
 request.setAttribute("parameter1", “hook to portlet”); 



And retrieve the same in your portlet like this

PortletSession portletSession = renderRequest.getPortletSession();  
portletSession.getAttribute("parameter1" ,PortletSession.APPLICATION_SCOPE) 
AMIT KUMAR SINGH, modificado hace 12 años.

RE: object sharing between hook and portlet

New Member Mensajes: 10 Fecha de incorporación: 28/03/12 Mensajes recientes
Awesome! It worked like kayam churna!!
Michael Bowen, modificado hace 11 años.

RE: object sharing between hook and portlet

New Member Mensaje: 1 Fecha de incorporación: 16/07/12 Mensajes recientes
I'm using liferay 6.0.5, and in order to properly store the session attribute - it required that I have my attribute name prefixed with LIFERAY_SHARED. So I needed:

session.setAttribute("LIFERAY_SHARED_myattribute", "some string value");


I found this helpful information at the following blog, which has some other good info: http://ceanot.blogspot.com/2011/11/sharing-session-data-between-portlet.html
thumbnail
Vivek Sharma, modificado hace 10 años.

RE: object sharing between hook and portlet

New Member Mensajes: 7 Fecha de incorporación: 28/04/14 Mensajes recientes
For me Kayam Churan is not working can u suggest some other solution. How Bout Khichadi...!!!!

Jokes Apart..!!

I tried the same thing but I'm not able to fetch the session variable in my portlet. I tried printing it, the value comes out to be NULL.

Can you help me out with this.??

Step 1:-
I have a hook in which I'm performing some post login tasks. I have added the lines of code that is given below to my doRun() method in the Hook:-

if (Validator.isNotNull(path))
{
HttpSession session = request.getSession();
session.setAttribute(WebKeys.LAST_PATH, new LastPath(StringPool.BLANK, path));
request.setAttribute("Parameter1", "Vivek Hook");

}


Step 2:-

I am trying to fetch the the Parameter in doView() of my Portlet class i.e CustomerSelectionPortlet.java

PortletSession portletSession = renderRequest.getPortletSession();
String customerSelectionSession=(String)portletSession.getAttribute("parameter1" ,PortletSession.APPLICATION_SCOPE);



Please suggest me a solution.
Shriharsh Ambhore, modificado hace 10 años.

RE: object sharing between hook and portlet

New Member Mensajes: 11 Fecha de incorporación: 5/03/13 Mensajes recientes
hey i tried your solution..but when i am trying to set the password in session from authenticateByScreenName method of login.event.pre hook the value received in my portlet is null..
thumbnail
Bhuwan Gautam, modificado hace 10 años.

RE: object sharing between hook and portlet

New Member Mensajes: 22 Fecha de incorporación: 16/01/13 Mensajes recientes
I am Using LiferayCE 6.1.1 and the following works for me to share object from Hooks to Portlet.In

Set value from Hook:

HttpSession session = request.getSession(false);
				request.setAttribute("param1", value);
				request.setAttribute("param2", value);


Get value from Portlet:


PortletRequest portletRequest = (PortletRequest)request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);
portletRequest.getAttribute("param1"));
portletRequest.getAttribute("param2"));


All the best emoticon
thumbnail
Raymond Gardner, modificado hace 10 años.

RE: object sharing between hook and portlet

Regular Member Mensajes: 118 Fecha de incorporación: 15/07/11 Mensajes recientes
Has anybody figured this out?

None of these suggestions are working for me.

I see "how to" steps to share session objects between one portlet in one war file and another portlet deployed in a separate war file.
But, we are seeking to share session objects between the hook and a portlet.

I don't believe the hook has access to the PortletRequest or the PortletSession. So, none of these suggested steps are working.
Montej Shah, modificado hace 8 años.

RE: object sharing between hook and portlet

Junior Member Mensajes: 48 Fecha de incorporación: 18/02/15 Mensajes recientes
Jitendra Rajput:
set parameter from hook ..

HttpSession session = request.getSession(false);  
 request.setAttribute("parameter1", “hook to portlet”); 



And retrieve the same in your portlet like this

PortletSession portletSession = renderRequest.getPortletSession();  
portletSession.getAttribute("parameter1" ,PortletSession.APPLICATION_SCOPE) 


above code will surely work but one extra thing you need to set below properties in liferay-portlet.xml
<private-session-attributes>false</private-session-attributes>