I'm trying out 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, which says that in order to embed a portlet widget in a page fragment, all I have to do is add the
"com.liferay.fragment.entry.processor.portlet.alias=my-custom-portlet"
property in the @Component
properties, where in this case, the alias (my-custom-portlet
) is the alias I will use to include the portlet in the fragment.
Then in my custom page fragment I have to include the lfr-widget
tag with the suffix defined by the com.liferay.fragment.entry.processor.portlet.alias
propertiy. So in my case, it should be<lfr-widget-my-custom-portlet />
.
The trouble is that I can't even create the page fragment with the above. I get the following error:
There is no widget available for alias my-custom-portlet.
If, on the other hand, I try it with a liferay portlet (such as <lfr-widget-nav/>
in their own example) the nav portlet is correctly displayed. Has anyone else tried? Any feedback at all would be appreciated.
I solved it. There were a couple things to consider.
First, I generated the mvc-portlet with Eclipse and it put old versions of the kernel dependencies in the build.gradle file. I changed them to:
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'
Second, in the portlet's @Component
annotation in the property { ... }
list I added:
"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",
in addition to what was already there.
So in my case, the @Component
looks like
@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 {
and the build.gradle
file looks like
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"
}