Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Riley Pickerl
Determine what page a portlet instance is on.
April 15, 2013 6:43 AM
Answer

Riley Pickerl

Rank: Junior Member

Posts: 50

Join Date: January 10, 2013

Recent Posts

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
RE: Determine what page a portlet instance is on.
April 15, 2013 6:52 AM
Answer

Rahul Sharma

Rank: Junior Member

Posts: 60

Join Date: January 10, 2012

Recent Posts

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.
Victor Zorin
RE: Determine what page a portlet instance is on.
April 15, 2013 2:37 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1176

Join Date: April 14, 2008

Recent Posts

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:
 1    public int countInstances(PortletConfig config, java.util.ArrayList<Long> links) throws NoLicenseInfoException {
 2        try {
 3            int totalCount = PortletPreferencesLocalServiceUtil
 4                    .getPortletPreferencesesCount();
 5            int currentIndex = 0;
 6            int instanceCount = 0;
 7            while (currentIndex <= totalCount) {
 8                int toIndex = currentIndex + 10;
 9                if (toIndex > totalCount) {
10                    toIndex = totalCount;
11                }
12                if (toIndex <= currentIndex) {
13                    break;
14                }
15                java.util.List<com.liferay.portal.model.PortletPreferences> list = PortletPreferencesLocalServiceUtil
16                        .getPortletPreferenceses(currentIndex, toIndex);
17               
18                java.util.Iterator<com.liferay.portal.model.PortletPreferences> it = list
19                        .iterator();
20                while (it.hasNext()) {
21                    com.liferay.portal.model.PortletPreferences pref = it
22                            .next();
23                    if (pref.getPortletId().startsWith(config.getPortletName())) {
24                        String settings = LayoutLocalServiceUtil.getLayout(pref.getPlid()).getTypeSettings();
25                        // max contain portlet Id to be counted
26                        if(settings.contains(config.getPortletName()))
27                        {
28                            if(links != null)
29                            {
30                                links.add(pref.getPlid());
31                            }
32                            instanceCount++;
33                        }
34                    }
35                    currentIndex++;
36                }
37            }
38            return instanceCount;
39        } catch (Exception e) {
40            throw new NoLicenseInfoException();
41        }
42    }
Riley Pickerl
RE: Determine what page a portlet instance is on.
April 17, 2013 7:15 AM
Answer

Riley Pickerl

Rank: Junior Member

Posts: 50

Join Date: January 10, 2013

Recent Posts

Great Thanks
Dave Weitzel
RE: Determine what page a portlet instance is on.
April 17, 2013 7:34 AM
Answer

Dave Weitzel

Rank: Regular Member

Posts: 181

Join Date: November 18, 2009

Recent Posts

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?