Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Hugo Passos
How to create, set and get global/session variables in Liferay?
May 1, 2011 3:51 AM
Answer

Hugo Passos

Rank: New Member

Posts: 11

Join Date: April 9, 2011

Recent Posts

Hi,

I'm using Liferay 6 bundled with Tomcat. I would like to know how can I manage variables in order that they can be acessible from any my jsp file.
How can make i it?
Tanweer .
RE: How to create, set and get global/session variables in Liferay?
May 1, 2011 8:04 AM
Answer

Tanweer .

Rank: Expert

Posts: 319

Join Date: March 11, 2010

Recent Posts

Hugo, You can make use of PortletSession

 1Put these below lines in liferay-portlet.xml
 2
 3<instanceable>true</instanceable>
 4<private-request-attributes>false</private-request-attributes>
 5<private-session-attributes>false</private-session-attributes>
 6
 7Setting the value :-
 8In your file where you want to set the value :- Create a PortletSession object and set your value there.
 9PortletSession ps = req.getPortletSession();
10ps.setAttribute(key, value, PortletSession.APPLICATION_SCOPE);
11
12where key is any meaningful name----eg. username
13value is the data which you want to set(access in other portlet) ----eg. tanweer
14PortletSession.APPLICATION_SCOPE specifies the scope.
15
16Getting the value :-
17ps.getAttribute(key, PortletSession.APPLICATION_SCOPE);
Sunil Rai
RE: How to create, set and get global/session variables in Liferay?
February 23, 2012 5:21 AM
Answer

Sunil Rai

Rank: Junior Member

Posts: 57

Join Date: January 31, 2012

Recent Posts

How can I display the user details in a JSP page by using Session. Say "Hello <Logged-In-User>". I am new to liferay so any guidance will be fruitful to me. Thanks
Jitendra Rajput
RE: How to create, set and get global/session variables in Liferay?
February 29, 2012 1:26 AM
Answer

Jitendra Rajput

Rank: Liferay Master

Posts: 858

Join Date: January 7, 2011

Recent Posts

Use themeDispaly ..


<liferay-theme:defineObjects /> place this tab in your jsp

and right code in this manner ..


Hello <%= themeDisplay.getUser().getFullName() %>
Jitendra Rajput
RE: How to create, set and get global/session variables in Liferay?
February 29, 2012 1:29 AM
Answer

Jitendra Rajput

Rank: Liferay Master

Posts: 858

Join Date: January 7, 2011

Recent Posts

agree with tanweer you can use portletSession to share information across application.

Look into below post for more information.
http://jbrajput.blogspot.com/2011/03/parameter-passing-across-two-war-file.html
Sunil Rai
RE: How to create, set and get global/session variables in Liferay?
March 21, 2012 6:27 AM
Answer

Sunil Rai

Rank: Junior Member

Posts: 57

Join Date: January 31, 2012

Recent Posts

I found the solution for my requirement that is same as your suggestion.
I got help on stackoverflow below is the mentioned link:
http://stackoverflow.com/questions/9410936/how-to-capture-liferay-logged-in-user-details-in-jsp-say-email-id-name-etc.

Here is the code:

<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
<liferay-theme:defineObjects />
<%= user.getEmailAddress() %>

I hope this will help someone. Thanks for your support @Jitendra Rajput