フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Riley Pickerl
Determine what page a portlet instance is on.
2013/04/15 6:43
答え

Riley Pickerl

ランク: Junior Member

投稿: 50

参加年月日: 2013/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
Rahul Sharma
RE: Determine what page a portlet instance is on.
2013/04/15 6:52
答え

Rahul Sharma

ランク: Junior Member

投稿: 60

参加年月日: 2012/01/10

最近の投稿

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.
2013/04/15 14:37
答え

Victor Zorin

ランク: Liferay Legend

投稿: 1170

参加年月日: 2008/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:
 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.
2013/04/17 7:15
答え

Riley Pickerl

ランク: Junior Member

投稿: 50

参加年月日: 2013/01/10

最近の投稿

Great Thanks
Dave Weitzel
RE: Determine what page a portlet instance is on.
2013/04/17 7:34
答え

Dave Weitzel

ランク: Regular Member

投稿: 169

参加年月日: 2009/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?