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
RE: Proper method to access a given jsp of the given portlet from any page?
Hello.
We created our own calendar displaying portlet and want to redirect the event url to a specified jsp file of our calendar portlet. We are trying to imitate the behavior of default Calendar portlet's notification url generating process but without any sucees. Liferay's version is 7.0 dxp .
We know that the url is generated in NotificationTemplateContextFactory.java's _getCalendarBookingURL method
private static String _getCalendarBookingURL( User user, long calendarBookingId) throws PortalException { Group group = _groupLocalService.getGroup( user.getCompanyId(), GroupConstants.GUEST); Layout layout = _layoutLocalService.fetchLayout( group.getDefaultPublicPlid()); String portalURL = _getPortalURL( group.getCompanyId(), group.getGroupId()); String layoutActualURL = PortalUtil.getLayoutActualURL(layout); String url = portalURL + layoutActualURL; String namespace = PortalUtil.getPortletNamespace( CalendarPortletKeys.CALENDAR); url = HttpUtil.addParameter( url, namespace + "mvcPath", "/view_calendar_booking.jsp");
which set the p_l_id of url to the layout id of the first page of the default site. When user click the event url, the default calendar portlet's /view_calendar_booking.jsp will be rendered in the first page of the default site, even if the default calendar portlet is NOT in that page. Actually if we replace the p_l_id to the layout id of any page in the guest site, the /view_calendar_booking.jsp will be rendered on that page, no matter where the default calendar portlet locates.
But when we replace the namespace to our calendar portlet and the mvcPath to the specified jsp file( by creating another EmailNotificationSender and assigning with a high service ranking value ), the url failed and resulted in 'You do not have the roles required to access this portlet'. It only works if we replace the p_l_id to the layout id of the page where we place our calendar displaying portlet.
We tried to created the resource-actions with VIEW permission to sitemembers and guests under src/main/resources/resource-actions/ and put it in the portlet.properties under src/main/resources but failed either. Is there any hint how can we achieve the goal? Thank you very much.
Assuming you are using MVCPortlet add the following property in your portlet class
|
See the reference below as to where to place the property.
https://dev.liferay.com/en/develop/tutorials/-/knowledge_base/7-0/adding-metadata
Regards,
Sandeep
The properties of MVCPortlet component are:
@Component( immediate = true, property = { "com.liferay.portlet.add-default-resource=true",
"com.liferay.portlet.display-category=category.sample", "com.liferay.portlet.instanceable=true", "javax.portlet.display-name=kview-scheduler",
"com.liferay.portlet.header-portlet-css=/css/main.css",
"javax.portlet.init-param.template-path=/", "javax.portlet.init-param.view-template=/view.jsp", "javax.portlet.name=" + KViewSchedulerPortletKeys.KviewScheduler, "javax.portlet.resource-bundle=content.Language", "javax.portlet.security-role-ref=administrator,guest,power-user,user" }, service = Portlet.class)
I'm not sure I fully understand. To recap:
1, you created your own portlet
2, you want to display your portlet on some layout
3, and set some URL parameter, for example MVC path
Correct?
Try to use com.liferay.portal.kernel.portlet.PortletURLFactory ... example: https://github.com/liferay/liferay-portal/blob/f1fac9af80650989a8230af8436c52f3d349fe1d/modules/apps/password-policies-admin/password-policies-admin-web/src/main/java/com/liferay/password/policies/admin/web/internal/portlet/configuration/icon/AssignMembersPortletConfigurationIcon.java#L67-L83
Don't forget to set MAXIMIZED, EXCLUSIVE or POP_UP state so that the portlet is visible!
Btw. if you want to display the portlet on any page, including those where it's not present, then you need "com.liferay.portlet.add-default-resource=true". The API above should add a token into the URL to avoid the "permission" exception.
HTH.
Thank you for the information. Unfortunately we can not use the same approach because we should create the link in the customized email notification sender where there is no portlet request object be found.
However, it is interesting that you have mentioned:
The API above should add a token into the URL to avoid the "permission" exception.which is not found in the url created by
https://github.com/liferay/liferay-portal/blob/f0cce6caed9c2a5941d592092df11639883e6d4a/modules/apps/calendar/calendar-service/src/main/java/com/liferay/calendar/internal/notification/NotificationTemplateContextFactory.java#L203-L235
It might be a hint for further research. Thank you.
Powered by Liferay™