如何通过代码添加嵌套portlet(liferay)

发布于 2024-12-19 20:14:28 字数 114 浏览 4 评论 0原文

我们在 liferay 中有一个叫做嵌套 portlet 的东西。我想通过代码动态添加此 portlet。有谁知道添加嵌套 portlet 并在其中添加其他 portlet 的代码吗?

谢谢 !!!

We have something called nested portlets in liferay. I want to add this portlet dynamically through code. Does anyone know the code for adding nested portlets, and add other portlets inside it?

Thanks !!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若无相欠,怎会相见 2024-12-26 20:14:28

对于完整的示例,我假设您想要使用另一个 portlet 操作处理程序将嵌套 portlet 添加到当前页面。 (如果在渲染操作中使用,则在页面的下一个视图之前您不会看到嵌套的 portlet)

将这些方法添加到您的代码中

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)
                throws PortalException, SystemException
{
    if (p_layout.isTypePortlet()) {
        final LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) p_layout.getLayoutType();

        final String portletId = layoutTypePortlet.addPortletId(p_userId, p_portletId, p_columnId, p_position, p_checkPermission);
        if (portletId != null) {
            final String rootPortletId = PortletConstants.getRootPortletId(portletId);
            final String portletPrimaryKey = PortletPermissionUtil.getPrimaryKey(p_layout.getPlid(), portletId);
            ResourceLocalServiceUtil.addResources(p_layout.getCompanyId(), p_layout.getGroupId(), 0, rootPortletId, portletPrimaryKey, true, true, true);
            LayoutLocalServiceUtil.updateLayout(p_layout.getGroupId(), p_layout.isPrivateLayout(), p_layout.getLayoutId(), p_layout.getTypeSettings());
        }
        return portletId;
    }

    return null;
}

private static void addNestedPortlet(final PortletRequest p_request) throws PortalException, SystemException {
    final ThemeDisplay themeDisplay = (ThemeDisplay) p_request.getAttribute(WebKeys.THEME_DISPLAY);
    final Layout layout = themeDisplay.getLayout();
    long userId = themeDisplay.getUserId();

    //create nested portlet and add it to "column-1"
    final String nestedPortletId = addPortlet(userId, layout, "118", "column-1", -1, false);

    //this will be used to target nested portlet's columns
    final String nestedColumnPrefix = "_" + nestedPortletId + "__";

    //default page layout (used by nested portlet) has two columns
    //we'll add two portlets (in this example two iframe portlets), one portlet to each column
    addPortlet(userId, layout, "48", nestedColumnPrefix + "column-1", -1, false);
    addPortlet(userId, layout, "48", nestedColumnPrefix + "column-2", -1, false);
}

如果您愿意(而且可能愿意)将嵌套 portlet 添加到另一个页面或不从 portlet 添加嵌套 portlet,您可以查找 Layout 和 User,而不是从 ThemeDisplay 获取它们。

for complete example i'll assume that you want to add nested portlet to current page using another portlets action handler. (if used from render action you would not see nested portlet until next view of the page)

Add these methods to your code

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)
                throws PortalException, SystemException
{
    if (p_layout.isTypePortlet()) {
        final LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) p_layout.getLayoutType();

        final String portletId = layoutTypePortlet.addPortletId(p_userId, p_portletId, p_columnId, p_position, p_checkPermission);
        if (portletId != null) {
            final String rootPortletId = PortletConstants.getRootPortletId(portletId);
            final String portletPrimaryKey = PortletPermissionUtil.getPrimaryKey(p_layout.getPlid(), portletId);
            ResourceLocalServiceUtil.addResources(p_layout.getCompanyId(), p_layout.getGroupId(), 0, rootPortletId, portletPrimaryKey, true, true, true);
            LayoutLocalServiceUtil.updateLayout(p_layout.getGroupId(), p_layout.isPrivateLayout(), p_layout.getLayoutId(), p_layout.getTypeSettings());
        }
        return portletId;
    }

    return null;
}

private static void addNestedPortlet(final PortletRequest p_request) throws PortalException, SystemException {
    final ThemeDisplay themeDisplay = (ThemeDisplay) p_request.getAttribute(WebKeys.THEME_DISPLAY);
    final Layout layout = themeDisplay.getLayout();
    long userId = themeDisplay.getUserId();

    //create nested portlet and add it to "column-1"
    final String nestedPortletId = addPortlet(userId, layout, "118", "column-1", -1, false);

    //this will be used to target nested portlet's columns
    final String nestedColumnPrefix = "_" + nestedPortletId + "__";

    //default page layout (used by nested portlet) has two columns
    //we'll add two portlets (in this example two iframe portlets), one portlet to each column
    addPortlet(userId, layout, "48", nestedColumnPrefix + "column-1", -1, false);
    addPortlet(userId, layout, "48", nestedColumnPrefix + "column-2", -1, false);
}

If you would like, and probably you would, to add nested portlet to another page or not from portlet, you can lookup Layout and User instead of getting them from ThemeDisplay.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文