liferay 7.1 b3 在片段中嵌入 portlet

liferay 7.1 b3 embed portlet in fragment

我正在尝试 liferay 7.1 b3 and I'd like to embed a portlet in a page fragment. I've taken a look at the most recent documentation available here,它说为了在页面片段中嵌入 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 />.

问题是我什至无法用上面的方法创建页面片段。我收到以下错误:

There is no widget available for alias my-custom-portlet.

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

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

首先,我使用 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'

其次,在 property { ... } 列表中的 portlet 的 @Component 注释中,我添加了:

"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"
}

我遇到了完全相同的问题,我的解决方案是避免在 portlet 名称中使用破折号!我花了很长时间才弄明白,所以我想我会 post 如果有人遇到同样的问题并且遇到这个 post.
因此,例如 "javax.portlet.name=my-custom-portlet" 写成 "javax.portlet.name=myCustomPortlet"
片段 属性 仍然可以包含任何破折号:"com.liferay.fragment.entry.processor.portlet.alias=my-custom-portlet"