Pregunta

I am having troubles with my Liferay-Portal after I included a function to generate the friendly URL. This is the function:

#set ($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))
#set ($layoutId = $getterUtil.getLong($image-link.getData()))
#set ($themeDisplay = $request.get('theme-display'))
#set ($currentPlid = $getterUtil.getLong($themeDisplay.get('plid')))
#set ($currentLayout = $layoutLocalService.getLayout($currentPlid))
#set ($layout = $layoutLocalService.getLayout($getterUtil.getLong($groupId), $currentLayout.isPrivateLayout(), $layoutId))
#set( $friendlyUrl = $layout.getFriendlyURL().replace("/", "") )

After a successful deployment, while surfing over the website my console outputs this:

09:15:26,279 ERROR [http-bio-8080-exec-83][LiferayMethodExceptionEventHandler:33] com.liferay.portal.NoSuchLayoutException: No Layout exists with the primary key 0
com.liferay.portal.NoSuchLayoutException: No Layout exists with the primary key 0

How do I get the layoutID of the current page and not of that image link?

¿Fue útil?

Solución

$themeDisplay is your friend and might have everything that you're looking for (including the current layout (page). The javadoc I linked is not that great, but the methods you'll find there are mostly descriptive and should give you a clue what kind of current context you can get from this object.

e.g. in a Theme, you can use $themeDisplay.getLayout().getRegularURL($request) to get the current page

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top