Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
PortletHub usage
While investigating adding Liferay support for the Vaadin platform we met with a problem where the Portlet 3.0 portlets are not added to the portlet registry on the client-side. What is required so that Liferay would generate the registration data to the client object(s) for the loaded portlets and also populate the base data?
As far as we have found there is no demo or usage of the PortletHub feature except in JavaScript tests for the hub implementation, but these use pre-generated mock data objects that are set and no where are the objects actually generated. This lead to the exception `can not read data for undefined` when trying to register with `portlet.register('portlet_id')` as the implementation expects there to always be available the objects `portlet.data`.
Making this even more complicated the registration will only succeed if the portlet has been pre set to the data as `portlet.data.pageRenderState.portlets[portlet_id]` which could be expected to be automatically populated with all portlet data on the page as the hub registration validates the portlet_id against this. If the id is not found the registration will fail with `Invalid portlet ID`.
With these bases set one could expect the portlet registration to the hub to be successfull, but then the hub still requires the allowed PortletModes and WindowStates to be set to the portlet_id object. Also to get hub.dispatchClientEvent to function the portlet_id needs to get an encodedActionURL or it will try to send the received event to `[server]/undefined.....` which will be rejected by the server with a 404
- Mikael
As far as we have found there is no demo or usage of the PortletHub feature except in JavaScript tests for the hub implementation, but these use pre-generated mock data objects that are set and no where are the objects actually generated. This lead to the exception `can not read data for undefined` when trying to register with `portlet.register('portlet_id')` as the implementation expects there to always be available the objects `portlet.data`.
Making this even more complicated the registration will only succeed if the portlet has been pre set to the data as `portlet.data.pageRenderState.portlets[portlet_id]` which could be expected to be automatically populated with all portlet data on the page as the hub registration validates the portlet_id against this. If the id is not found the registration will fail with `Invalid portlet ID`.
With these bases set one could expect the portlet registration to the hub to be successfull, but then the hub still requires the allowed PortletModes and WindowStates to be set to the portlet_id object. Also to get hub.dispatchClientEvent to function the portlet_id needs to get an encodedActionURL or it will try to send the received event to `[server]/undefined.....` which will be rejected by the server with a 404
- Mikael
Hi Mikael,
what Liferay Portal version you are using?
what Liferay Portal version you are using?
liferay-ce-portal-7.2.1-ga2
Hi Mikael,
I recommend that you take a look at the Portlet Hub Demo available from the Apache Pluto project:
In addition to running the Portlet 3.0 TCK tests, we test the Portlet Hub Demo before we do any release.
If you still can't get things working after examining the demo, then please let us know and we'd be happy to get you moving forward.
Thanks for using Liferay and Portlet 3.0!
Neil
I recommend that you take a look at the Portlet Hub Demo available from the Apache Pluto project:
In addition to running the Portlet 3.0 TCK tests, we test the Portlet Hub Demo before we do any release.
If you still can't get things working after examining the demo, then please let us know and we'd be happy to get you moving forward.
Thanks for using Liferay and Portlet 3.0!
Neil
Also, if you build the Portlet Hub Demo from source in order to try the resulting WAR artifact in Liferay, please remember to specify the liferay profile when building it:
mvn -P liferay clean package
mvn -P liferay clean package
Hi.
We have our portlet support working on Pluto with the portletHub
see our multimodule demo project https://github.com/vaadin/addressbook-portlet
This will not work as is on liferay, as it requires changes to vaadin-portlet,
but after those are made this is deployable on Liferay 7.2.1-ga2.
The main problem is that there should apparently be some data populated on the
client-side for Liferay that doesn't get populated. Is this linked somehow to
the fact that we do not build portlets using JSP?
Pluto adds registration data for the portlets added to the page and `portal.register`
works as expected.
As stated above for Liferay `portlet.register` expects that there exists in `window` scope an object
`portlet.data.pageRenderState.portlets` with portlet data as objects named with the portletID
inside portlets.
Running the addressbook-demo on liferay will fail the registration to the hub on the client
when no `portlet` object has been created.
So our main question is that what triggers the generation and population of
pageRenderState data and portlet state information for the current view.
- Mikael
We have our portlet support working on Pluto with the portletHub
see our multimodule demo project https://github.com/vaadin/addressbook-portlet
This will not work as is on liferay, as it requires changes to vaadin-portlet,
but after those are made this is deployable on Liferay 7.2.1-ga2.
The main problem is that there should apparently be some data populated on the
client-side for Liferay that doesn't get populated. Is this linked somehow to
the fact that we do not build portlets using JSP?
Pluto adds registration data for the portlets added to the page and `portal.register`
works as expected.
As stated above for Liferay `portlet.register` expects that there exists in `window` scope an object
`portlet.data.pageRenderState.portlets` with portlet data as objects named with the portletID
inside portlets.
Running the addressbook-demo on liferay will fail the registration to the hub on the client
when no `portlet` object has been created.
So our main question is that what triggers the generation and population of
pageRenderState data and portlet state information for the current view.
- Mikael
Hi Mikael,
Are you requesting that the PortletHub be added as a client-side dependency?
Unless the PortletHub is added as a client-side dependency, Liferay Portal will not initialize certain client-side variables such as "portlet":
https://github.com/liferay/liferay-portal/blob/7.2.1-ga2/portal-web/docroot/html/common/themes/top_head.jsp#L171-L199
Here is an example of how to add the dependency via the @PortletConfiguration annotation:
https://github.com/apache/portals-pluto/blob/1ba39987873c3ba7eb6f0c42f155d882d8f87ac5/portlet-tck_3.0/V3HeaderPortletTests/src/main/java/javax/portlet/tck/portlets/HeaderPortletTests_SPEC15_HeaderResponse2.java#L56-L59
A second way of doing it would be to specify it as a client-side dependency in portlet.xml:
https://github.com/apache/portals-pluto/blob/9f2c66f3c4d194aae0b985a6552c1b9b985801a8/demo/v3-demo-portlet/src/main/webapp/WEB-INF/portlet.xml#L45-L49
A third way to do it would be to do it programmatically by calling HeaderResponse.addDependency("PortletHub", "javax.portlet", "3.0.0"). For a close (but not exact) example, here is how you can add jQuery as a dependency:
https://github.com/apache/portals-pluto/blob/9f2c66f3c4d194aae0b985a6552c1b9b985801a8/demo/applicant-mvcbean-cdi-thymeleaf-portlet/src/main/java/org/apache/portals/pluto/demo/applicant/mvcbean/cdi/thymeleaf/portlet/ApplicantPortlet.java#L63-L66
Please let me know if that helps.
Kind Regards,
Neil
Are you requesting that the PortletHub be added as a client-side dependency?
Unless the PortletHub is added as a client-side dependency, Liferay Portal will not initialize certain client-side variables such as "portlet":
https://github.com/liferay/liferay-portal/blob/7.2.1-ga2/portal-web/docroot/html/common/themes/top_head.jsp#L171-L199
Here is an example of how to add the dependency via the @PortletConfiguration annotation:
https://github.com/apache/portals-pluto/blob/1ba39987873c3ba7eb6f0c42f155d882d8f87ac5/portlet-tck_3.0/V3HeaderPortletTests/src/main/java/javax/portlet/tck/portlets/HeaderPortletTests_SPEC15_HeaderResponse2.java#L56-L59
A second way of doing it would be to specify it as a client-side dependency in portlet.xml:
https://github.com/apache/portals-pluto/blob/9f2c66f3c4d194aae0b985a6552c1b9b985801a8/demo/v3-demo-portlet/src/main/webapp/WEB-INF/portlet.xml#L45-L49
A third way to do it would be to do it programmatically by calling HeaderResponse.addDependency("PortletHub", "javax.portlet", "3.0.0"). For a close (but not exact) example, here is how you can add jQuery as a dependency:
https://github.com/apache/portals-pluto/blob/9f2c66f3c4d194aae0b985a6552c1b9b985801a8/demo/applicant-mvcbean-cdi-thymeleaf-portlet/src/main/java/org/apache/portals/pluto/demo/applicant/mvcbean/cdi/thymeleaf/portlet/ApplicantPortlet.java#L63-L66
Please let me know if that helps.
Kind Regards,
Neil
Hi.
We are requesting the loading of PortletHub through the header with `headerResponse.addDependency("PortletHub", "javax.portlet", "3.0.0");` and the hub is available on the page, but the portlet data is not populated to the page.
If `top_head.jsp` is the only place that populates the data how should that be added or should it be added automatically when PortletHub is requested to be loaded? Is there something we should request to get the top_head to load? Or should we wait for something to be finished, so that data gets populated before trying to register our portlet to the hub?
- Mikael
We are requesting the loading of PortletHub through the header with `headerResponse.addDependency("PortletHub", "javax.portlet", "3.0.0");` and the hub is available on the page, but the portlet data is not populated to the page.
If `top_head.jsp` is the only place that populates the data how should that be added or should it be added automatically when PortletHub is requested to be loaded? Is there something we should request to get the top_head to load? Or should we wait for something to be finished, so that data gets populated before trying to register our portlet to the hub?
- Mikael
Hi Mikael,I verified that the HeaderResponse.addDependency("PortletHub", "javax.portlet", "3.0.0") approach does not work and documented it in the following issue:
https://issues.liferay.com/browse/LPS-107438
Please "watch" the issue in JIRA for updates.For now, I recommend that you proceed with either the @PortletConfiguration annotation on a Java source class or the <dependency> method in portlet.xml
Kind Regards,Neil
https://issues.liferay.com/browse/LPS-107438
Please "watch" the issue in JIRA for updates.For now, I recommend that you proceed with either the @PortletConfiguration annotation on a Java source class or the <dependency> method in portlet.xml
Kind Regards,Neil
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™