Search code examples
liferayliferay-6portlet

Preferences.store() throws UnsupportedOperationException in Liferay 6.2 GA2


I have a JSF portlet that was working in 6.1. When I upgraded to 6.2 CE GA2, preferences.store() throws UnsupportedOperationException. I get preferences object as follows:

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();

// Get portlet preferences
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
PortletPreferences portletPreferences = portletRequest.getPreferences();

And I have following attributes in liferay-portlet.xml:

<preferences-unique-per-layout>true</preferences-unique-per-layout>
<preferences-owned-by-group>false</preferences-owned-by-group>

I found some related threads and bug reports (https://issues.liferay.com/browse/LPS-42458). I can confirm that when I have true this code works. Issue is fixed but I am still getting this problem. Also I tried to implement that hook workaround but that interface seems to be changed in GA2.

Also when I get the preferences store using the following code, store() executes without exception but it seems that it is access different values than the preferences I get using the code at the beginning of the post.

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();

// Get portlet preferences
PortletPreferences portletPreferences = null;
try {
    portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(
                                portletRequest, PortletIdUtil.getPorletId());
} catch (PortalException | SystemException e) {
    e.printStackTrace();
}

if(portletPreferences == null) {
    return;
}

Any suggestions?


Solution

  • I can't confirm that the interface has changed. I didn't fully test, but the workaround mentioned in LPS-42458 works for me without compiler errors. When you fix the imports on that overridden service wrapper, make sure to choose the correct SystemException, as Liferay confusingly has two of them. com.liferay.portal.kernel.exception.SystemException was required to make the code compile for me