How to get portal preferences setting from table on Liferay

时间:2017-07-12 08:02:00

标签: java liferay liferay-6

I am a Liferay user, I need to get some of properties in my liferay portal, such as dl.file.max.size,users.image.max.size... in portal preferences table. Everything setting with key instead add to portal-ext.properties.

And how to update back changed value?

I tried some code

PortalPreferences portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(request);

long usersImageMaxSize = GetterUtil.getLong(portalPreferences.getValue(PropsKeys.USERS_IMAGE_MAX_SIZE,"0"),0);

but get nothing.

Please help!.

Thanks advance.

(Liferay portal 6.2)

2 个答案:

答案 0 :(得分:2)

我找到了结果。这里是代码示例:

        PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences();

        String value= portletPreferences.getValue(PropsKeys.DL_FILE_MAX_SIZE, "0");

        System.out.println(value);


        portletPreferences.setValue(PropsKeys.DL_FILE_MAX_SIZE,"123456789") 
        portletPreferences.store();

        value = portletPreferences.getValue(PropsKeys.DL_FILE_MAX_SIZE, "0");

        System.out.println(value);

感谢Daniele的帮助。

答案 1 :(得分:1)

您使用的代码错误。 PortletPreferencesFactoryUtil不是正确的util类(它适用于portlet首选项)。

相反,您必须使用此代码:

long usersImageMaxSize = GetterUtil.getLong(PropsUtil.get(PropsKeys.USERS_IMAGE_MAX_SIZE));