Fórum
way to discover pages a portlet is on
Jack Bakker, modificado 11 Anos atrás.
way to discover pages a portlet is on
Liferay Master Postagens: 978 Data de Entrada: 03/01/10 Postagens Recentes
looking for a way to list pages a custom portlet might be on
jelmer kuperus, modificado 11 Anos atrás.
RE: way to discover pages a portlet is on
Liferay Legend Postagens: 1191 Data de Entrada: 10/03/10 Postagens Recentes
Victor Zorin, modificado 11 Anos atrás.
RE: way to discover pages a portlet is on
Liferay Legend Postagens: 1228 Data de Entrada: 14/04/08 Postagens Recentes
This is how we count instances of a specific portlet . You should be able to use similar approach to find out urls from layouts. I suppose you should not be really making such calls every time. Only when you would like to know.
public int countInstances(PortletConfig config, java.util.ArrayList<long> links) throws NoLicenseInfoException {
try {
int totalCount = PortletPreferencesLocalServiceUtil
.getPortletPreferencesesCount();
int currentIndex = 0;
int instanceCount = 0;
while (currentIndex <= totalCount) {
int toIndex = currentIndex + 10;
if (toIndex > totalCount) {
toIndex = totalCount;
}
if (toIndex <= currentIndex) {
break;
}
java.util.List<com.liferay.portal.model.portletpreferences> list = PortletPreferencesLocalServiceUtil
.getPortletPreferenceses(currentIndex, toIndex);
java.util.Iterator<com.liferay.portal.model.portletpreferences> it = list
.iterator();
while (it.hasNext()) {
com.liferay.portal.model.PortletPreferences pref = it
.next();
if (pref.getPortletId().startsWith(config.getPortletName())) {
String settings = LayoutLocalServiceUtil.getLayout(pref.getPlid()).getTypeSettings();
// max contain portlet Id to be counted
if(settings.contains(config.getPortletName()))
{
if(links != null)
{
links.add(pref.getPlid());
}
instanceCount++;
}
}
currentIndex++;
}
}
return instanceCount;
} catch (Exception e) {
throw new NoLicenseInfoException();
}
}
</com.liferay.portal.model.portletpreferences></com.liferay.portal.model.portletpreferences></long>
Vitaliy Koshelenko, modificado 11 Anos atrás.
RE: way to discover pages a portlet is on
Expert Postagens: 319 Data de Entrada: 25/03/11 Postagens Recentes
Hi, Jack.
I have done it in a way like this:
I have done it in a way like this:
String PORTLET_ID = "customPortlet";
//Iterate over layouts
List<layout> layouts = LayoutLocalServiceUtil.getLayouts(groupId, false);
for (Layout layout : layouts) {
if (layout.getLayoutType() != null) {
//Iterate over all Slider portlets
DynamicQuery portletDynamicQuery = DynamicQueryFactoryUtil.forClass(Portlet.class, classLoader).add(PropertyFactoryUtil.forName("portletId").like(PORTLET_ID + "%"));
List<portlet> portlets = PortletLocalServiceUtil.dynamicQuery(portletDynamicQuery);
for (Portlet portlet : portlets) {
//Get layout properties - in order to obtain full portletId
HashMap<string, string> layoutPropertiesMap = layout.getTypeSettingsProperties();
for (String layoutValue : layoutPropertiesMap.values()) {
if (layoutValue.startsWith(PORTLET_ID)) {
// the portletId is the initial part before first "," if extra info is present
String portletId = layoutValue.contains(StringPool.COMMA) ?
layoutValue.substring(0, layoutValue.indexOf(StringPool.COMMA)) :
layoutValue;
//your porlet with this portletId is on this layout in this case
//...
}
}
}
}
}</string,></portlet></layout>
Jack Bakker, modificado 11 Anos atrás.
RE: way to discover pages a portlet is on
Liferay Master Postagens: 978 Data de Entrada: 03/01/10 Postagens Recentes
thanks guys