掲示板

Determine what page a portlet instance is on.

11年前 に Riley Pickerl によって更新されました。

Determine what page a portlet instance is on.

Junior Member 投稿: 50 参加年月日: 13/01/10 最新の投稿
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
11年前 に Rahul Sharma によって更新されました。

RE: Determine what page a portlet instance is on.

Junior Member 投稿: 59 参加年月日: 12/01/11 最新の投稿
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
11年前 に Victor Zorin によって更新されました。

RE: Determine what page a portlet instance is on.

Liferay Legend 投稿: 1228 参加年月日: 08/04/14 最新の投稿
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>
11年前 に Riley Pickerl によって更新されました。

RE: Determine what page a portlet instance is on.

Junior Member 投稿: 50 参加年月日: 13/01/10 最新の投稿
Great Thanks
thumbnail
11年前 に Dave Weitzel によって更新されました。

RE: Determine what page a portlet instance is on.

Regular Member 投稿: 208 参加年月日: 09/11/18 最新の投稿
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?