1

我正在尝试根据当前登录用户的站点/社区名称过滤 Web 内容,下面的代码写在 portal_normal.vm 中。我正在使用自己的自定义主题。我的门户应用程序中有 3 个站点,即 Global、Liferay、myCustomSite。

我有默认的 liferay 用户“test”作为 Liferay 站点的一部分,我自己的用户作为“myCustomSite”的一部分。

    #set ($group_local_service = $serviceLocator.findService("com.liferay.portal.service.GroupLocalService"))
    #set ($user_groups = $group_local_service.getUserGroups($user.getUserId()))
    #foreach($user_groups 中的$user_group)
    #if ($user_group.isRegularSite())
        #set ($journal_article_local_service = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
        #set ($journal_articles = $journal_article_local_service.getArticles($user_group.getGroupId()))
        #foreach($journal_articles 中的 $article)
            #if($article.getStatus() ==0)
                #set ($VOID = $velocityPortletPreferences.setValue('groupId',$user_group.getGroupId().toString()))
                #set ($VOID = $velocityPortletPreferences.setValue('articleId', $article.getArticleId().toString()))
                #set ($VOID = $velocityPortletPreferences.setValue('portletSetupShowBorders', 'false'))
                #set ($portlet_id = '56')
                #set ($my_portlet_id = "${portlet_id}_INSTANCE_${article.getArticleId()}")
                $theme.runtime($my_portlet_id, "", $velocityPortletPreferences.toString())
                $velocityPortletPreferences.reset()
            #结尾
        #结尾
        #结尾
    #结尾

当我运行上面的代码时,我能够获取自定义站点中的所有文章,但在动态添加它们时会遇到问题。我收到一个错误,例如

11:06:39,420 INFO [JournalContentImpl:306] 获取文章显示 {10184, 14853, }
11:06:39,421 WARN [JournalContentImpl:317] 无法显示 10184 14853 en_US

“10184”是默认的liferay 组/站点ID,“14853”是我在我的自定义站点下的文章ID。我不知道为什么它使用liferay 站点ID,即使我传递了当前用户的站点ID。

当我检查“ThemeDisplay.getScopGroupId”时,我总是得到 liferay 站点 ID。我正在使用liferay 6.2 GA2。任何指针都会有帮助。谢谢。

4

1 回答 1

0

Let me explain what you're doing in this code. First: What Liferay technically calls group, typically manifests in a site (simplified, but enough for the purpose of this answer)

What your code is doing is:

Get *all* sites that the current User is member of
For each of those sites:
   Get *all* articles from CMS for this site
   For each of these articles:
       if the article is workflow-approved (status==0)
           include a Web Content Display Portlet, properly configured

As you can see these are two nested loops, enumerating a potentially large number of sites and articles - and I assume this is not what you want to do.

As you just state that your code doesn't do what you expect (but not what you actually expect), I hope that this explanation is enough to point you to the root cause of your problem.

I'm assuming that you probably want to show a single article somewhere, as it's embedded in the theme, thus on every page. As a theme renders on every single page request, you should make sure that you don't enumerate all sites and articles for each single request.

于 2014-06-26T09:07:12.417 回答