4

如何将自定义 portlet 添加到控制面板部分?我看过各种教程,但都是 liferay 6.2。如何在liferay 7中完成它?提前谢谢..

4

2 回答 2

3

在 Liferay 7 中,如果您使用捆绑包(例如,通过Blade 工具创建),您可以让它与面板应用程序一起使用。面板应用程序将 portlet 映射到控制面板中的某个位置。

假设您有一个由 Blade 生成的 portlet,如下所示:

@Component(
    immediate = true,
    property = {
        "com.liferay.portlet.display-category=category.sample",
        "com.liferay.portlet.instanceable=false",
        "javax.portlet.name=cpportlet",
        "javax.portlet.display-name=Control Panel Portlet",
        "javax.portlet.security-role-ref=power-user,user"
    },
    service = Portlet.class
)
public class CpPortlet extends GenericPortlet {

    @Override
    protected void doView(
            RenderRequest renderRequest, RenderResponse renderResponse)
        throws IOException, PortletException {

        PrintWriter printWriter = renderResponse.getWriter();

        printWriter.print("cp-portlet Portlet - Hello World!");
    }

}

PanelApp现在您只需创建另一个实现该服务的 OSGi 组件:

@Component(
    immediate = true,
    property = {
        "panel.app.order:Integer=10000",   // Defines position in list
        "panel.category.key=" + PanelCategoryKeys.SITE_ADMINISTRATION_CONTENT // To appear in the "Content" session
    },
    service = PanelApp.class
)
public class CpPanelApp extends BasePanelApp {

    @Override
    public String getPortletId() {
        return "cpportlet";    // Same name of the portlet.
    }

    @Override
    @Reference(
        target = "(javax.portlet.name=cpportlet)",
        unbind = "-"
    )
    public void setPortlet(Portlet portlet) {
        super.setPortlet(portlet);
    }

}

要编译它,您将依赖“应用程序列表应用程序”API - 我们在那里找到了PanelApp类。因此,只需将此依赖项添加到您的build.gradle中,如下所示:

dependencies {
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
    compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
    compileOnly group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"

    compileOnly group: "com.liferay", name: "com.liferay.application.list.api", version: "2.0.0"  // Dependency added
}

现在部署它,portlet 将出现在清单中:

在此处输入图像描述

这只是基本思想——文档对此很有指导意义。

于 2016-11-04T18:27:20.927 回答
1

您可以通过组件的属性定义控制面板类别: com.liferay.portlet.control-panel-entry-category=<String> com.liferay.portlet.control-panel-entry-weight=<double>

请参考此处列出的映射: https ://dev.liferay.com/develop/reference/-/knowledge_base/7-0/portlet-descriptor-to-osgi-service-property-map

于 2016-11-04T17:46:47.493 回答