0

在 Liferay 6.2挂钩中,我想知道 portlet 类型(资产发布者/Web 内容显示)。Portlet 名称对我没有帮助,因为用户可能使用了自定义标题,在这种情况下,我将无法访问“资产发布者”/“Web 内容显示”。

我想要 Portlet 类型的确切挂钩文件位置是:/html/portlet/portlet_css/view.jsp

4

2 回答 2

0

好吧,如果不连接 Liferay 的其他部分,您将无法获得它(在 java 代码中)。Portlet“Portlet CSS”是通过 javascript 填充的,因此显然不需要发送 portletid 作为参数。

要获取 portletId,您还应该挂钩 /html/js/liferay/look_and_feel.js

autoLoad: false,
showLoading: false,
data: {
    p_l_id: themeDisplay.getPlid(),
    p_p_id: 113,
    p_p_state: EXCLUSIVE,
    doAsUserId: themeDisplay.getDoAsUserIdEncoded()
},
uri: themeDisplay.getPathMain() + '/portal/render_portlet'

修改它是这样的

autoLoad: false,
showLoading: false,
data: {
    p_l_id: themeDisplay.getPlid(),
    p_p_id: 113,
    p_p_state: EXCLUSIVE,
    doAsUserId: themeDisplay.getDoAsUserIdEncoded(),
    _113_portletId: instance._portletId
},
uri: themeDisplay.getPathMain() + '/portal/render_portlet'

添加了逗号_113_portletId: instance._portletId

之后,您可以放入 hooked /html/portlet/portlet_css/view.jsp

String portletId = (String) renderRequest.getParameter("portletId");

资产发布者的 portletId 类似于101_INSTANCE_reKokSN3aDaL

Web 内容显示的 portletId 将类似于 56_INSTANCE_dxNxXuQ7ZuvB

因此您可以测试 portletId 是否以 101、56、... 开头

您还可以通过以下方式获取 Portlet 对象

PortletLocalServiceUtil.getPortletById(portletId);

更新(回答评论中的问题):

此 Portlet 不适合此类用途,一旦加载,它就会以 html 呈现,并且所有修改都是使用 javascript 进行的。

在向服务器发出页面加载 XHR 请求并呈现“/html/portlet/portlet_css/view.jsp”后首次打开“外观”时。第二次(对于同一页面上的另一个 portlet),javascript 为另一个(或相同的) portlet 准备模式,“/html/portlet/portlet_css/view.jsp”将不会再次呈现。

要强制重新呈现“/html/portlet/portlet_css/view.jsp”,请再次修改“/html/js/liferay/look_and_feel.js”。

之后(在我的源代码中是第 136 行)

if (!content) {
    content = A.Node.create('<div class="loading-animation" />');
} 

添加这个

if (instance._currentPopup) {
    A.one("#" + instance._currentPopup.get("id")).remove()
    instance._currentPopup = null;
}

应该是之前

if (!instance._currentPopup) {
    instance._currentPopup = Liferay.Util.Window.getWindow(
    ...

清除 Liferay 和浏览器缓存。

于 2016-12-08T15:59:09.467 回答
0

您可以从 ThemeDisplay 上下文对象和 PortletDisplay 中获取 PortletDisplay 对象,您可以获取 Title、PortletName 等。

请注意,themeDisplay 已经可用并在您的 jsp /html/portlet/portlet_css/view.jsp 中使用 PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); String title=portletDisplay.getTitle(); String portletName=portletDisplay.getPortletName();

于 2016-12-08T15:30:00.377 回答