Get portlet/page containing web content in Liferay

荒凉一梦 提交于 2019-12-24 08:59:56

问题


I'm trying to make the Liferay (6.0.6) Asset Publisher publish all changes across multiple communities on the portal homepage. By clicking on a link the user is supposed to be redirected to another community and see the new web content. The problem is that the default behaviour of asset publisher (even with the hook to gather info from all communities) tries to get the url by searching the group of the current page (in which the content is not). I decided to change the jsp showing the page to search all pages across all communities and find the first one containing the portlet with the desired web content. So

  1. How could I get the portlet containing the web content by journal id of the web content?
  2. How could I get the page containing the portlet?

Thanks


回答1:


The PortletPreferences table in the database contains the configurations of each portlet in the system. The configuration of an articleId for a Web Content Display portlet is stored as a preference in this table. If you look at that table, there are 3 important columns:

  • plid contains the id of the Layout (=page) on which the portlet was dropped.
  • portletid contains the instance id of the portlet. For Web Content Display portlet, this ID has the format 56_INSTANCE_XXXX where XXXX is a unique hash.
  • preferences is an XML formatted string of all preferences and their values for this portlet.

An example of the preferences XML:

<portlet-preferences>
    <preference><name>group-id</name><value>10139</value></preference>
    <preference><name>article-id</name><value>14295</value></preference>
</portlet-preferences>

So it's just a question of getting your SQL queries right. As far as I know, there is no service you can call directly for this.

SELECT l.friendlyURL
FROM PortletPreferences p, Layout l
WHERE p.plid=l.plid 
AND p.portletid LIKE '56_INSTANCE_%' 
AND p.preferences LIKE '<preference><name>article-id</name><value>14295</value></preference>';



回答2:


Something like the following allows you to find the Layout on which an article is Rendered.

List<Long> layoutIds = JournalContentSearchLocalServiceUtil.getLayoutIds(groupId, false, articleId);
long layoutId = 0;

if (!layoutIds.isEmpty()) {
  layoutId = layoutIds.get(0).longValue();
  Layout layout = LayoutLocalServiceUtil.getLayout(groupId, false, layoutId);
  String url = PortalUtil.getLayoutURL(layout, themeDisplay);
  ...
}


来源:https://stackoverflow.com/questions/8397679/get-portlet-page-containing-web-content-in-liferay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!