【问题标题】:Liferay: No Layout exists with the primary key 0Liferay:主键为0的布局不存在
【发布时间】:2013-08-16 04:06:19
【问题描述】:

在包含生成友好 URL 的功能后,我的 Liferay-Portal 出现问题。这是函数:

#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("/", "") )

成功部署后,在浏览网站时,我的控制台会输出以下内容:

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

如何获取当前页面的 layoutID 而不是该图片链接的?

【问题讨论】:

  • 您的$layoutId 被初始化为#set ($layoutId = $getterUtil.getLong($image-link.getData())) - 这恰好是0
  • 该图像甚至不存在。我复制了一些示例页面的代码。
  • 如果这是在模板中,则模板下的示例结构显然有一个名为 image-link 的字段,而您的结构没有。否则,请指定您在何处使用此速度代码。此外,它可能有助于您尝试实现的目标,我们可能会提供一些提示,说明如何解决潜在问题比使用您选择的实现路径解决问题更容易。请用根本问题重新表述问题。
  • @OlafKock 我重新表述了我的问题。如果有更好的方法来实现这一点,我很乐意听到。

标签: java content-management-system liferay velocity portal


【解决方案1】:

$themeDisplay 是您的朋友,可能拥有您正在寻找的一切(包括当前布局(页面)。我链接的 javadoc 不是那么好,但您会发现那里的方法大多是描述性的,应该给你一个线索,你可以从这个对象中获得什么样的当前上下文。

例如在 Theme 中,可以使用$themeDisplay.getLayout().getRegularURL($request) 获取当前页面

【讨论】:

    猜你喜欢
    • 2018-10-19
    • 2013-11-11
    • 2014-10-08
    • 1970-01-01
    • 2013-04-11
    • 1970-01-01
    • 2016-06-14
    • 2023-03-23
    • 2011-05-20
    相关资源
    最近更新 更多