简体   繁体   中英

Liferay Portlet prefrences

I'm trying to allow to Liferay's administrator to configure a Portlet. I have created the configuration page and configuration action.

The problem is: I can save the configuration and the portlet use this configuration correctly, but I can't get this values when I enter again in configuration.

 <%  
     String somePreferenceKey_cfg = portletPreferences.getValue("salesMin","");
 %>
 ......
 <aui:input name="salesMin" type="text" value="<%= somePreferenceKey_cfg %>" />

somePreferenceKey_cfg is empty.

Somebody have any idea about what can I do? Thanks, Iván.

Either use:

PortletPreferences preferences = renderRequest.getPreferences();
String somePreferenceKey_cfg = preferences.getValue("salesMin", "default_value");

Or:

String somePreferenceKey_cfg =
    GetterUtil.getString(portletPreferences.getValue("salesMin", "default_value"));

to get value from preference. Also, set some default value in-case preference are not manually stored.

How you are instantiating the portletPreferences object? Try obtaining the portletId and call PortletPreferences API of Liferay. For example:

PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(request,portletId);

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