Search code examples
javaliferayportletportal

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


Solution

  • 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