Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Add nested portlets through code in liferay

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 713
    Comment on it

    Hello Guys


    We can add nested portlets through code in liferay. Liferay provide this funcationlity, for complete example I will assume that you want to add nested portlet to current page using another portlets action handler.


    Add these methods to your code :

    1. private static String addPortlet(final long p_userId, final Layout p_layout, final String p_portletId, final String p_columnId, final int p_position, final boolean p_checkPermission)
    2. throws PortalException, SystemException
    3. {
    4. if (p_layout.isTypePortlet()) {
    5. final LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) p_layout.getLayoutType();
    6.  
    7. final String portletId = layoutTypePortlet.addPortletId(p_userId, p_portletId, p_columnId, p_position, p_checkPermission);
    8. if (portletId != null) {
    9. final String rootPortletId = PortletConstants.getRootPortletId(portletId);
    10. final String portletPrimaryKey = PortletPermissionUtil.getPrimaryKey(p_layout.getPlid(), portletId);
    11. ResourceLocalServiceUtil.addResources(p_layout.getCompanyId(), p_layout.getGroupId(), 0, rootPortletId, portletPrimaryKey, true, true, true);
    12. LayoutLocalServiceUtil.updateLayout(p_layout.getGroupId(), p_layout.isPrivateLayout(), p_layout.getLayoutId(), p_layout.getTypeSettings());
    13. }
    14. return portletId;
    15. }
    16.  
    17. return null;
    18. }
    19.  
    20. private static void addNestedPortlet(final PortletRequest p_request) throws PortalException, SystemException {
    21. final ThemeDisplay themeDisplay = (ThemeDisplay) p_request.getAttribute(WebKeys.THEME_DISPLAY);
    22. final Layout layout = themeDisplay.getLayout();
    23. long userId = themeDisplay.getUserId();
    24.  
    25. //create nested portlet and add it to "column-1"
    26. final String nestedPortletId = addPortlet(userId, layout, "118", "column-1", -1, false);
    27.  
    28. //this will be used to target nested portlet's columns
    29. final String nestedColumnPrefix = "_" + nestedPortletId + "__";
    30.  
    31. //default page layout (used by nested portlet) has two columns
    32. //we'll add two portlets (in this example two iframe portlets), one portlet to each column
    33. addPortlet(userId, layout, "48", nestedColumnPrefix + "column-1", -1, false);
    34. addPortlet(userId, layout, "48", nestedColumnPrefix + "column-2", -1, false);
    35. }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: