Alimozzaman

Liferay : add a child page of any community programitically

Posted on: January 29, 2011

We can add any child page of any community from admin panel in the following way. See the picture. But we can do the same thing programmatically.

Here is the way to add a child page:

1.  Overwrite your EditGroupAction.java page into EXT.

2. Add the following lines  into updateGroup function.

Group group = GroupServiceUtil.addGroup(
name, description, type, friendlyURL, active, serviceContext);

after this line add ……..

boolean privateLayout = false;
long parentLayoutId = 0;
String childpageName = “childPage”;
String titleChild = “childPage”;
String descriptionChild = “childPage”;
String type = LayoutConstants.TYPE_PORTLET;
boolean hidden = false;
String friendlyURL = “/childPage”;

Layout layout = LayoutLocalServiceUtil.addLayout(userId,
group.getGroupId(),
privateLayout,
parentLayoutId,
childpageName,
titleChild,
descriptionChild,
type,
hidden,
friendlyURL);

/****You can add custom template and also u can add portlet  to it******/

LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

layoutTypePortlet.setLayoutTemplateId(0, “layouttpl-id”, false);
layoutTypePortlet.addPortletId(0, “20”, “column-1”, -1,false);
LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());

//Then you can update the permission

updatePermissions(layout,true);

/*********End up the coding************/

//Here is the update permission method

public void updatePermissions(Layout layout, boolean addDefaultActionIds)
throws Exception {

long companyId = layout.getCompanyId();

Role role = RoleLocalServiceUtil
.getRole(companyId, RoleConstants.GUEST);

String[] actionIds = new String[0];

String name = Layout.class.getName();
int scope = ResourceConstants.SCOPE_INDIVIDUAL;
String primKey = String.valueOf(layout.getPrimaryKey());

Resource resource = ResourceLocalServiceUtil.getResource(companyId,
name, scope, primKey);

if (addDefaultActionIds) {
actionIds = new String[] { ActionKeys.VIEW };
}

PermissionLocalServiceUtil.setRolePermissions(role.getRoleId(),
actionIds, resource.getResourceId());

PermissionLocalServiceUtil.setRolePermissions(RoleLocalServiceUtil.getRole(companyId,
RoleConstants.POWER_USER).getRoleId(),
actionIds, resource.getResourceId());

PermissionLocalServiceUtil.setRolePermissions(RoleLocalServiceUtil.getRole(companyId,
RoleConstants.COMMUNITY_MEMBER).getRoleId(),
actionIds, resource.getResourceId());
}

3.  You can check the child page like http://localhost:8080/web/<community-name>/childPage or from admin panel.

Enjoy!!

Make comment to make this more helpful  to the community.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Top Rated

Advertisements
%d bloggers like this: