Reputation: 10241
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
Upvotes: 4
Views: 3697
Reputation: 1
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
Upvotes: 0
Reputation: 2509
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
Upvotes: 5