Fórumok

Determine what page a portlet instance is on.

Riley Pickerl, módosítva 10 év-val korábban

Determine what page a portlet instance is on.

Junior Member Bejegyzések: 50 Csatlakozás dátuma: 2013.01.10. Legújabb bejegyzések
Hello,
I am wondering if there is a way to determine what page a portlet instance is on. I need a way to determine where the portlet is because I need to create custom variables that are set individually on each instance. I have looked through the PortalUtil methods but have not seen anything that would help me with this. Does anyone know if this is possible or how to do this?

Thanks,
Riley Pickerl
Rahul Sharma, módosítva 10 év-val korábban

RE: Determine what page a portlet instance is on.

Junior Member Bejegyzések: 59 Csatlakozás dátuma: 2012.01.11. Legújabb bejegyzések
Hi,

You can do this by iterating typesettings of the layouts as per the groupid and check if the typesettings contains your portlet name or not.

Hope that helps.
thumbnail
Victor Zorin, módosítva 10 év-val korábban

RE: Determine what page a portlet instance is on.

Liferay Legend Bejegyzések: 1228 Csatlakozás dátuma: 2008.04.14. Legújabb bejegyzések
The sample method that calculates the number of total instances of portlet deployed on the portal as well as providing list of pages where these instances deployed to.
We use it in custom portlet licensing implementation. The portletConfig param is for the portlet which is investigated for:
	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 &lt;= totalCount) {
				int toIndex = currentIndex + 10;
				if (toIndex &gt; totalCount) {
					toIndex = totalCount;
				}
				if (toIndex &lt;= 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>
Riley Pickerl, módosítva 10 év-val korábban

RE: Determine what page a portlet instance is on.

Junior Member Bejegyzések: 50 Csatlakozás dátuma: 2013.01.10. Legújabb bejegyzések
Great Thanks
thumbnail
Dave Weitzel, módosítva 10 év-val korábban

RE: Determine what page a portlet instance is on.

Regular Member Bejegyzések: 208 Csatlakozás dátuma: 2009.11.18. Legújabb bejegyzések
i have been using :
LayoutLocalServiceUtil.getDefaultPlid(groupId, false , "34");

to locate the layout (web page) that has the shopping cart on it (portletId 34)

the true/false is a public/private layout "switch".
It seems this is what you were wanting to get?