Fórum
How to convert from liferay.PortletPreferences to javax.PortletPreferences?
Cameron McBride, modificado 12 Anos atrás.
How to convert from liferay.PortletPreferences to javax.PortletPreferences?
Expert Postagens: 269 Data de Entrada: 08/02/11 Postagens Recentes
The normal way to set and retrieve portlet preferences is with javax.portlet.PortletPreferences. I want to look up some preferences outside of that portlet. To do that it seems like I need to use the liferay objects and classes like com.liferay.portal.model.PortletPreferences. There are lots of goodies like PortalPreferencesLocalServiceUtil, PortalPreferencesFinderUtil, PortalPreferencesFactoryUtil.
How do I take a liferay PortletPreferences object and convert it to the javax PortletPreferences to easily pull some preferences out or set them?
I can do a getPreferences() - String and see my preferences, which are returned in an xml format:
I could parse that xml but that doesn't seem like the best way.
How do I take a liferay PortletPreferences object and convert it to the javax PortletPreferences to easily pull some preferences out or set them?
I can do a getPreferences() - String and see my preferences, which are returned in an xml format:
<portlet-preferences><preference><name>my_name</name><value>1,2</value></preference></portlet-preferences>
I could parse that xml but that doesn't seem like the best way.
Toni Pérez Rodil, modificado 12 Anos atrás.
RE: How to convert from liferay.PortletPreferences to javax.PortletPreferen
New Member Postagens: 9 Data de Entrada: 02/08/10 Postagens Recentes
Hello, Cameron!
If you have access to the "companyId", I would give a try to "com.liferay.portal.service.PortletPreferencesLocalServiceUtil#getPreferences( long companyId, long ownerId, int ownerType, long plid,java.lang.String portletId) throws com.liferay.portal.kernel.exception.SystemException".
Apart of the"companyId", you can get the needed parameters from the com.liferay.portal.model.PortletPreferences object.
HTH.
Regards.
--
Toni Pérez Rodil
B2B 2000
If you have access to the "companyId", I would give a try to "com.liferay.portal.service.PortletPreferencesLocalServiceUtil#getPreferences( long companyId, long ownerId, int ownerType, long plid,java.lang.String portletId) throws com.liferay.portal.kernel.exception.SystemException".
Apart of the"companyId", you can get the needed parameters from the com.liferay.portal.model.PortletPreferences object.
HTH.
Regards.
--
Toni Pérez Rodil
B2B 2000
Cameron McBride, modificado 12 Anos atrás.
RE: How to convert from liferay.PortletPreferences to javax.PortletPreferen
Expert Postagens: 269 Data de Entrada: 08/02/11 Postagens Recentes
That worked great, thanks! I couldn't tell from Eclipse which of those methods returned a javax object. Since most of them return liferay objects I didn't look at the source, my fault.
Here is some gnarly code that takes a group and a portlet type, loops through every page in the group, checks for that portlet, gets the preferences and prints a value from them. Maybe this thing will help someone one day.
Here is some gnarly code that takes a group and a portlet type, loops through every page in the group, checks for that portlet, gets the preferences and prints a value from them. Maybe this thing will help someone one day.
Group group = null;
try {
group = GroupLocalServiceUtil.getGroup(groupId);
} catch (Exception e) {
e.printStackTrace();
}
if (group == null) {
return retMap;
}
List<layout> layouts = new ArrayList<layout>();
if (group.getPublicLayoutsPageCount() > 0) {
System.out.println("0. page count: "+group.getPublicLayoutsPageCount());
try {
layouts.addAll(LayoutLocalServiceUtil.getLayouts(group.getGroupId(), false));
} catch (Exception e) {
e.printStackTrace();
}
}
if (group.getPrivateLayoutsPageCount() > 0) {
try {
layouts.addAll(LayoutLocalServiceUtil.getLayouts(group.getGroupId(), true));
} catch (SystemException e) {
e.printStackTrace();
}
}
for (Layout layout : layouts)
{
System.out.println("has a layout");
LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
if (layoutTypePortlet != null)
{
System.out.println("1");
List<portlet> portlets = null;
try {
portlets = layoutTypePortlet.getAllPortlets();
} catch (Exception e) {
e.printStackTrace();
}
if (portlets != null) {
for (Portlet portlet : portlets)
{
System.out.println("3 - " + portlet.getPluginId() + " - " + portlet.getPortletId());
if (portlet.getPluginId().equals(portletId)) {
System.out.println("4");
List<com.liferay.portal.model.portletpreferences> prefsList = null;
try {
prefsList = PortletPreferencesLocalServiceUtil.getPortletPreferences(layout.getPlid(), portlet.getPortletId());
} catch (Exception e) {
e.printStackTrace();
}
if (prefsList != null) {
for (com.liferay.portal.model.PortletPreferences prefs : prefsList) {
PortletPreferences portletPrefs = null;
try {
portletPrefs = PortletPreferencesLocalServiceUtil.getPreferences(companyId, prefs.getOwnerId(), prefs.getOwnerType(), layout.getPlid(), portlet.getPortletId());
} catch (Exception e) {
e.printStackTrace();
}
if (portletPrefs != null) {
String links = portletPrefs.getValue(QuickLinksTools.QUICK_LINKS, "");
System.out.println("Links: " + links);
}
}
}
}
}
}
}
}</com.liferay.portal.model.portletpreferences></portlet></layout></layout>