Foros de discusión

Portlet Preferences Limitation

Triveni B, modificado hace 7 años.

Portlet Preferences Limitation

New Member Mensajes: 21 Fecha de incorporación: 24/03/11 Mensajes recientes
Hi,

I have created portlet A in webpage1 and portlet B in webpage2.
Webpage2 is childpage of webpage1.
I have stored some data using portlet preferences in portlet A edit mode
Now my query is shall I use/get portlet A preferences data in portlet B(its in webpage2)- Technically is it feasible?

I have tried above approach but values not loading in portlet B.

Please suggest.

Thanks,
Triveni.
thumbnail
Pankaj Kathiriya, modificado hace 7 años.

RE: Portlet Preferences Limitation

Liferay Master Mensajes: 722 Fecha de incorporación: 5/08/10 Mensajes recientes
You can use API methods from com.liferay.portal.service.PortletPreferencesLocalServiceUtil to get portlet-preference values of any portlet.
e.g
getPortletPreferences(long plid, java.lang.String portletId)

OR
getPortletPreferences(int ownerType, long plid, java.lang.String portletId)
Triveni B, modificado hace 7 años.

RE: Portlet Preferences Limitation

New Member Mensajes: 21 Fecha de incorporación: 24/03/11 Mensajes recientes
Pankaj Kathiriya:
You can use API methods from com.liferay.portal.service.PortletPreferencesLocalServiceUtil to get portlet-preference values of any portlet.
e.g
getPortletPreferences(long plid, java.lang.String portletId)

OR
getPortletPreferences(int ownerType, long plid, java.lang.String portletId)


Thanks Pankaj

I have tried your suggested approach and added below line of code in portlet B render method(its in different webpage)
PortletPreferences prefs = PortletPreferencesLocalServiceUtil.getPreferences(themeDisplay.getScopeGroupId(),PortletKeys.PREFS_OWNER_ID_DEFAULT, PortletKeys.PREFS_OWNER_TYPE_LAYOUT, plId, PORTLET_ID);
String productCardDDLRenderVal= prefs.getValue("productCardDDLPrefVal", StringPool.TRUE);
String keyInvestorDDLRenderVal=prefs.getValue("keyInvestorDDLPrefVal", StringPool.TRUE);

I tried both methods of PortletPreferencesLocalServiceUtil - getPortletPreferences and getPrefernces

But still im not getting Portlet A Preferences in Portlet B.

Please let me know did I miss anything.
thumbnail
Olaf Kock, modificado hace 7 años.

RE: Portlet Preferences Limitation

Liferay Legend Mensajes: 6396 Fecha de incorporación: 23/09/08 Mensajes recientes
Triveni B:
Technically is it feasible?


My opinion: No. That's not what PortletPreferences are there for. Use a different way to store data that you'll need in both portlets.
Varun Jain, modificado hace 7 años.

RE: Portlet Preferences Limitation

New Member Mensajes: 10 Fecha de incorporación: 26/04/12 Mensajes recientes
Refer below code and it will definitely work.

long plid =PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(),"portletId");

PortletPreferences preferences =PortletPreferencesLocalServiceUtil.fetchPreferences(themeDisplay.getCompanyId(), 0,PortletKeys.PREFS_OWNER_TYPE_LAYOUT, plid,
"portletId");


And make sure that preferences are saved at least once.
Triveni B, modificado hace 7 años.

RE: Portlet Preferences Limitation

New Member Mensajes: 21 Fecha de incorporación: 24/03/11 Mensajes recientes
Varun Jain:
Refer below code and it will definitely work.

long plid =PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(),"portletId");

PortletPreferences preferences =PortletPreferencesLocalServiceUtil.fetchPreferences(themeDisplay.getCompanyId(), 0,PortletKeys.PREFS_OWNER_TYPE_LAYOUT, plid,
"portletId");


And make sure that preferences are saved at least once.


Thanks Varun for reply

Its worked partially for me.

First time I have stored preferences in portlet A(value1, value2), and based on above approach I am getting those preferences values in Portlet B(value1,value2).

Second time I changed and saved preferences in portlet A(value3,value4) but this time when I am rendering to portlet B, loading old preferences values (value1,value2), its not updating with new values in portlet B

Please suggest .
Varun Jain, modificado hace 7 años.

RE: Portlet Preferences Limitation

New Member Mensajes: 10 Fecha de incorporación: 26/04/12 Mensajes recientes
Can you please share the code ?
Triveni B, modificado hace 7 años.

RE: Portlet Preferences Limitation

New Member Mensajes: 21 Fecha de incorporación: 24/03/11 Mensajes recientes
Varun Jain:
Can you please share the code ?


Saving preferences in portletA

PortletPreferences prefs = actionRequest.getPreferences();
if(Val1!=null)
{
prefs.setValue("Val1PrefVal",Val1);
prefs.store();
}
if(Val2!=null)
{
prefs.setValue("Val2PrefVal",Val2);
prefs.store();
}

Fetching Portlet A preferences in Portlet B

ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
long plid =PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(),PortletA_ID);
PortletPreferences prefs =PortletPreferencesLocalServiceUtil.fetchPreferences(themeDisplay.getCompanyId(), 0,PortletKeys.PREFS_OWNER_TYPE_LAYOUT, plid,PortletA_ID);
String renderVal1= prefs.getValue("Val1PrefVal", StringPool.TRUE);
String renderVal2=prefs.getValue("Val2PrefVal", StringPool.TRUE);

And I observed this fetching API behaves strangely, sometimes loading portlet A pref values & sometimes loading null values.

Do I need to add any configuration in portlet.xml such as preferences-company-wide, preferences-unique-per-layout, I read in below blog
https://web.liferay.com/web/pmesotten/blog/-/blogs/user-specific-versus-shared-portlet-preferences-part-1

Please do needful.