Pages

Wednesday, 17 April 2013

Adding portlet to the portal Directly

here i am explaining How to add portlet to webpage  immediately after deploying the portlet
 its so simple
just past the below code in your action class
 public void init() throws PortletException {
       viewjsp=getInitParameter("view-jsp");
           try {              
               Company companyqq = CompanyLocalServiceUtil.getCompanyByWebId("vinod.com");
                Role adminRole = RoleLocalServiceUtil.getRole(companyqq.getCompanyId(),"Administrator");
                List<User> adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());                
                PrincipalThreadLocal.setName(adminUsers.get(0).getUserId());
                PermissionChecker permissionChecker =PermissionCheckerFactoryUtil.create(adminUsers.get(0), clearRequestParameters);
                PermissionThreadLocal.setPermissionChecker(permissionChecker);                            
                            long plid = 17817;
                           Layout layout = LayoutLocalServiceUtil.getLayout(plid);
                            LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet)layout.getLayoutType();
                           String portletId = "pagination_WAR_paginationportlet_INSTANCE_cVJ3";
                           String targetColumn = "column-1";
                           layoutTypePortlet.addPortletId(12770,portletId,targetColumn,-1);                          
                           layoutTypePortlet.resetStates();
                           LayoutServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings());
                       } catch (Exception e) {
                           e.printStackTrace();
               }
}

i hope this will be help full for you in feature.....
thank u

No comments:

Post a Comment