Fórum

object sharing between hook and portlet

AMIT KUMAR SINGH, modificado 12 Anos atrás.

object sharing between hook and portlet

New Member Postagens: 10 Data de Entrada: 28/03/12 Postagens Recentes
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 12 Anos atrás.

RE: object sharing between hook and portlet

Expert Postagens: 310 Data de Entrada: 07/07/10 Postagens Recentes
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 12 Anos atrás.

RE: object sharing between hook and portlet

New Member Postagens: 10 Data de Entrada: 28/03/12 Postagens Recentes
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 12 Anos atrás.

RE: object sharing between hook and portlet

Expert Postagens: 310 Data de Entrada: 07/07/10 Postagens Recentes
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 12 Anos atrás.

RE: object sharing between hook and portlet

Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens Recentes
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 12 Anos atrás.

RE: object sharing between hook and portlet

New Member Postagens: 10 Data de Entrada: 28/03/12 Postagens Recentes
Awesome! It worked like kayam churna!!
Michael Bowen, modificado 11 Anos atrás.

RE: object sharing between hook and portlet

New Member Mensagem: 1 Data de Entrada: 16/07/12 Postagens Recentes
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 9 Anos atrás.

RE: object sharing between hook and portlet

New Member Postagens: 7 Data de Entrada: 28/04/14 Postagens Recentes
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 10 Anos atrás.

RE: object sharing between hook and portlet

New Member Postagens: 11 Data de Entrada: 05/03/13 Postagens Recentes
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 10 Anos atrás.

RE: object sharing between hook and portlet

New Member Postagens: 22 Data de Entrada: 16/01/13 Postagens Recentes
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 10 Anos atrás.

RE: object sharing between hook and portlet

Regular Member Postagens: 118 Data de Entrada: 15/07/11 Postagens Recentes
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 8 Anos atrás.

RE: object sharing between hook and portlet

Junior Member Postagens: 48 Data de Entrada: 18/02/15 Postagens Recentes
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>