com.liferay.portal.model.Layout layout = ((com.liferay.portal.theme.ThemeDisplay)themeDisplay).getLayout();
javax.portlet.PortletPreferences portletSetup = com.liferay.portlet.PortletPreferencesFactoryUtil
.getLayoutPortletSetup(layout, "portlet_id");
here themeDisplay is user specific themeDispaly as a result it load user specific preference.
try {
portletSetup.setValue("key", "value");
portletSetup.getValue("key", "default value");
} catch (ReadOnlyException e1) {
e1.printStackTrace();
}
Load global preference:
javax.portlet.PortletPreferences portletSetup = actionRequest.getPreferences();
try {
portletSetup.setValue("key", "value");
portletSetup.getValue("key", "default value");
} catch (ReadOnlyException e1) {
e1.printStackTrace();
}
here actionRequest may be javax.portlet.RenderRequest or javax.portlet.ActionRequest or javax.portlet.PortletRequestYou need to set the following properties in liferay-portlet.xml or in case of overridden in ext liferay-portlet-ext.xml, if want to set company wise/ global preference for portlet:
<preferences-company-wide>true</preferences-company-wide>
<preferences-unique-per-layout>false</preferences-unique-per-layout>
No comments:
Post a Comment