Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Petr Vasek
Custom user global storage !
September 13, 2012 5:29 AM
Answer

Petr Vasek

Rank: Junior Member

Posts: 68

Join Date: June 26, 2012

Recent Posts

Hi all, i am beginer and i cerate my custom global storage by service-builder and one singelton class. By service-builder i create 2 methods:
1
2 MyFunctions.getGlobalStorageValue(String);
3MyFunctions.setGlobalStorageValue(String, Object);


storage as singelton class - classic solution:

 1
 2package cz.ictb.algo.core;
 3
 4import java.util.HashMap;
 5public class GlobalStorage {
 6   
 7     private HashMap<String,Object> _store;
 8     private static GlobalStorage _instance = null;
 9   
10   
11     private GlobalStorage() {
12         _store = new  HashMap<String,Object>();
13     }
14         
15     public static GlobalStorage getInstance() {
16         
17         if (_instance == null) {
18             _instance = new GlobalStorage();
19         }
20         return _instance;    
21     }
22    
23     public void setValue(String _key, Object _value) {
24         _store.put(_key, _value);
25     }
26    
27     public Object getValue(String _key) {
28         return _store.get( _key);
29     }
30}

I thought that every loged user will be their global storage. But this is VERY BIG MISTAKE :0(( Storage is shared!

Global storage i useig in portlets, extensions plugins etc.

Please guys , how can i do ti that every user have their storage. ??

Thank you very much and so sorry for my english

Peter
Petr Vasek
RE: Custom user global storage !
September 13, 2012 7:11 AM
Answer

Petr Vasek

Rank: Junior Member

Posts: 68

Join Date: June 26, 2012

Recent Posts

Please help me this is very vey big problem for me :0(
Petr Vasek
RE: Custom user global storage !
September 13, 2012 9:53 PM
Answer

Petr Vasek

Rank: Junior Member

Posts: 68

Join Date: June 26, 2012

Recent Posts

I elucidate my problem.

When user loging to liferay i want save one string information about user and this information i need get anywhere in liferay, etc in EXT plugin ..file PortalLDAPUtil. I need only some tool how set and get to some storage. This is basic think in web developing, this is not posible in Liferay? emoticon

Please help
Tomas Polesovsky
RE: Custom user global storage !
September 14, 2012 12:00 AM
Answer

Tomas Polesovsky

LIFERAY STAFF

Rank: Liferay Master

Posts: 612

Join Date: February 13, 2009

Recent Posts

Ahoj Petře,

did you know that we have also czech forum?

The simplest solution is to put your HashMap into a user session. When you use Hook you can create an Action that will be called after user login (using "login.events.post" in <portal-properties>...</portal-properties> file of your hook). There you can add whatever you want into the session.

In most cases when you don't have request object you can access the session using PortalSessionThreadLocal.

-- tom+
Petr Vasek
RE: Custom user global storage !
September 14, 2012 12:23 AM
Answer

Petr Vasek

Rank: Junior Member

Posts: 68

Join Date: June 26, 2012

Recent Posts

If its it, so you are Liferay Legend for me emoticon

I am gooing try it!
Petr Vasek
RE: Custom user global storage !
September 14, 2012 1:28 AM
Answer

Petr Vasek

Rank: Junior Member

Posts: 68

Join Date: June 26, 2012

Recent Posts

Its not working :0((

I tried rewrite LoginAction , where i set session:

1
2HttpSession session = PortalSessionThreadLocal.getHttpSession();
3session.setAttribute("ATTR1", "TEST");


and next in etc. PortalLDAPUtil

1
2HttpSession session = PortalSessionThreadLocal.getHttpSession();
3System.out.println("DEBUG: PRITN SESSION = " +  (String)session.getAttribute("ATTR1")); <- NullPointerException

Dou you know why, please?