Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Akash Mohan Patil
How to get Current page Scope Id
July 6, 2012 1:14 AM
Answer

Akash Mohan Patil

Rank: Junior Member

Posts: 70

Join Date: December 12, 2010

Recent Posts

Hi Friends,

I stuck up in a problem from so many days. actually i wanted to create a blog Entry Programmatic.

So i Used the following code:

 1
 2            ServiceContext serviceContext = new ServiceContext();
 3            serviceContext.setAddCommunityPermissions(true);
 4            serviceContext.setAddGuestPermissions(true);
 5            String layoutUuid= themeDisplay.getLayout().getUuid();
 6            long groupId =0;
 7            try {
 8                Layout scopeLayout = LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(layoutUuid, themeDisplay.getLayout().getGroupId());
 9                if(!scopeLayout.hasScopeGroup()){
10                    String name = String.valueOf(scopeLayout.getPlid());
11                    GroupLocalServiceUtil.addGroup(themeDisplay.getUserId(), Layout.class.getName(),scopeLayout.getPlid(), name, null, 0, null, true, null);
12                }
13            } catch (PortalException e1) {
14                // TODO Auto-generated catch block
15                e1.printStackTrace();
16            } catch (SystemException e1) {
17                // TODO Auto-generated catch block
18                e1.printStackTrace();
19            }


This is working properly., but adding the blog to community Blog. I need is to add blog to the current page scope. So how to get the Current Page scope. please help me to solve this.

Thanks,
Akash patil
kavya v
RE: How to get Current page Scope Id
July 26, 2012 3:15 AM
Answer

kavya v

Rank: New Member

Posts: 3

Join Date: February 23, 2011

Recent Posts

Hi Akash,


Did you solved the problem?I want to add current page scope to portlets pragmatically ,please help me......

Thanks in advance.
Nisarg Parikh
RE: How to get Current page Scope Id
July 27, 2012 4:03 AM
Answer

Nisarg Parikh

Rank: Expert

Posts: 262

Join Date: December 30, 2009

Recent Posts

Blog portlet should be on that particular page with current(page) scope defined.

You can try using below code, that might help you.

 1
 2
 3              Group curGroup = themeDisplay.getScopeGroup();
 4         if (curGroup.isLayout()) {
 5            scopeLayout = LayoutLocalServiceUtil.getLayout(curGroup.getClassPK());
 6            curGroup = scopeLayout.getGroup();
 7        }
 8   
 9        List<Layout> curGroupLayouts = new ArrayList<Layout>();
10        List<Layout> scopeLayouts = new ArrayList<Layout>();
11       
12        curGroupLayouts.addAll(LayoutLocalServiceUtil.getLayouts(curGroup.getGroupId(), false));
13        curGroupLayouts.addAll(LayoutLocalServiceUtil.getLayouts(curGroup.getGroupId(), true));
14
15        for (Layout curGroupLayout : curGroupLayouts)
16        {
17            if (curGroupLayout.hasScopeGroup())
18            {
19                scopeLayouts.add(curGroupLayout);
20            }
21        }
22
23               for (Layout curScopeLayout : scopeLayouts)
24        {
25            String scopeGroupName = HtmlUtil.escape(curScopeLayout.getName());
26            if( scopeGroupName.indexOf("check your page name here") > 0 )
27            {
28                curScopeGroupId = curScopeLayout.getScopeGroup().getGroupId();
29                break;
30            }
31        }
32         
33          



Hope this helps.

-Nisarg