简体   繁体   中英

How to set portal wide global variables in liferay?

I am currently working on a portal and I need to use Liferay as the Portal server.

My application will be having some global settings, which i need to access in all the portlets in my portal.

what is the best pratice to load such configuration settigs? I want those configuration settings to be read from a configuration file/database. but it should be read only once at the application startup. I dont want the settings to be read from database/file for each request.

Also, I would be using velocity framework for templates, can i read the same global variables in my velocity templates?

Can i put those global variables in my portal-ext.properties file and if Yes, how can i load default values in it?

Any other approaches would also help,

Thanks in advance

Add the following to portal-ext.properties :

my.key=myValue

You can implement PropsKeys for the key:

public class ExtPortalKeys implements PropsKeys {
public static final String MY_KEY = "my.key";
}

and then call:

PrefsPropsUtil.getString(companyId, ExtPortalKeys.MY_KEY);

regards

One Approach would be to use login post action hook.

Define your class to the portal-ext.properties file

login.events.post=com.xxx.PostLoginAction

In the class you can read the configuration or properties from file/database. You can set these up as some global session values which can be shared by all the portlets.

More information on post login action and session sharing is available in the links below

http://www.liferay.com/community/wiki/-/wiki/Main/Custom+Post-login+Redirect

http://www.liferay.com/community/wiki/-/wiki/Main/Session+Sharing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM