温馨提示:本文翻译自stackoverflow.com,查看原文请点击:java - liferay 7.1 b3 embed portlet in fragment
java liferay-7 portlet liferay

java - liferay 7.1 b3 如何在fragment中嵌入portlet

发布于 2020-03-30 21:32:22

我正在尝试liferay 7.1 b3,我想将portlet嵌入页面片段中。我看过这里提供的最新文档,该文档说,为了将portlet小部件嵌入页面片段中,我要做的就是添加

"com.liferay.fragment.entry.processor.portlet.alias=my-custom-portlet"

属性中的@Component属性,在这种情况下,别名(my-custom-portlet)是我将用来在片段中包含portlet的别名。

然后,在我的自定义页面片段中,我必须包含lfr-widget带有com.liferay.fragment.entry.processor.portlet.alias属性定义的后缀标记因此,就我而言,应该是<lfr-widget-my-custom-portlet />

麻烦的是,我什至无法使用上述内容创建页面片段。我收到以下错误:

没有可用于别名my-custom-portlet的小部件。

另一方面,如果我尝试使用liferay Portlet(例如<lfr-widget-nav/>在他们自己的示例中),则可以正确显示nav portlet。还有其他人尝试过吗?任何反馈都将不胜感激。

查看更多

提问者
William Burnham
被浏览
22
William Burnham 2018-06-18 23:40

我解决了 有几件事情要考虑。

首先,我使用Eclipse生成了mvc-portlet,并将旧版本的内核依赖项放入build.gradle文件中。我将它们更改为:

compileOnly group: 'com.liferay.portal', name: 'com.liferay.portal.kernel', version: '3.0.1'
compileOnly group: 'com.liferay.portal', name: 'com.liferay.util.taglib', version: '3.0.0'

第二,@Componentproperty { ... }列表的portlet 注释中添加了:

"com.liferay.fragment.entry.processor.portlet.alias=my-custom-portlet",
"com.liferay.portlet.application-type=widget",
"com.liferay.portlet.application-type=full-page-application",
"javax.portlet.name=my-custom-portlet",

除了已经存在的东西。

所以在我的情况下,@Component看起来像

@Component(
    immediate = true,
    property = {
        "com.liferay.portlet.display-category=category.sample",
        "com.liferay.portlet.instanceable=true",
        "javax.portlet.display-name=my-custom-portlet Portlet",
        "javax.portlet.init-param.template-path=/",
        "javax.portlet.init-param.view-template=/view.jsp",
        "javax.portlet.resource-bundle=content.Language",
        "javax.portlet.security-role-ref=power-user,user",
        "javax.portlet.name=my-custom-portlet",
        "com.liferay.fragment.entry.processor.portlet.alias=my-custom-portlet",
        "com.liferay.portlet.application-type=widget",
        "com.liferay.portlet.application-type=full-page-application",
        "com.liferay.portlet.add-default-resource=true"
    },
    service = Portlet.class
)
public class MyCustomPortlet extends MVCPortlet {

build.gradle文件看起来像

dependencies {
    compileOnly group: 'com.liferay.portal', name: 'com.liferay.portal.kernel', version: '3.0.1'
    compileOnly group: 'com.liferay.portal', name: 'com.liferay.util.taglib', version: '3.0.0'

    compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
    compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
    compileOnly group: "jstl", name: "jstl", version: "1.2"
    compileOnly group: "org.osgi", name: "osgi.cmpn", version: "6.0.0"
}