Message Boards

Getting session value in Angular/ React portlet - LR7.2

Deepak P, modified 3 Years ago.

Getting session value in Angular/ React portlet - LR7.2

New Member Posts: 2 Join Date: 5/15/20 Recent Posts
Hi All, i set a session value in postlogin hook like this. 
HttpSession ses = lifecycleEvent.getRequest().getSession();
ses.setAttribute("PING_URL","somevalue");
I want to read this session value in my React portlet which is a pure javascript portlet. how to achieve this ?
thumbnail
Mohammed Yasin, modified 3 Years ago.

RE: Getting session value in Angular/ React portlet - LR7.2

Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts
Hi ,
You may not be able to read session attributes from js file , may be u need to make a server call  (ajax)  to read the values. but in case your JavaScript code residing inside a jsp then you can read it . 
Deepak P, modified 3 Years ago.

RE: Getting session value in Angular/ React portlet - LR7.2

New Member Posts: 2 Join Date: 5/15/20 Recent Posts
Thanks Yasin for the response, in my case its  a pure javascript react project without a jsp or java controller, what is the ideal way to get session in this case ?
thumbnail
Mohammed Yasin, modified 3 Years ago.

RE: Getting session value in Angular/ React portlet - LR7.2

Liferay Master Posts: 591 Join Date: 8/8/14 Recent Posts
You can make a ajax call with resource url and read the session attributes.
https://help.liferay.com/hc/en-us/articles/360018159491-MVC-Resource-Command