使用liferay dockbar通知

使用liferay dockbar通知,liferay,Liferay,我想在教程之后使用liferay通知功能。和以前的许多人一样,我成功地增加了通知的数量,但是通知消息没有显示出来 我试图通过添加日志输出来检查UserNotificationHandler的方法(getBody,getLink,…)是否被调用,并且它们根本没有被调用,甚至UserNotificationHandler的构造函数也没有被调用 因此,我得出结论,我的通知已写入数据库,但找不到我的UserNotificationHandler类 在我的项目中,我把 将用户通知定义放入 project/

我想在教程之后使用liferay通知功能。和以前的许多人一样,我成功地增加了通知的数量,但是通知消息没有显示出来

我试图通过添加日志输出来检查
UserNotificationHandler
的方法(
getBody
getLink
,…)是否被调用,并且它们根本没有被调用,甚至
UserNotificationHandler
的构造函数也没有被调用

因此,我得出结论,我的通知已写入数据库,但找不到我的
UserNotificationHandler

在我的项目中,我把 将用户通知定义放入

project/src/main/resources. 
它们看起来像:

<?xml version="1.0"?>
<!DOCTYPE user-notification-definitions PUBLIC "-//Liferay//DTD User Notification Definitions 6.2.0//EN" "http://www.liferay.com/dtd/liferay-user-notification-definitions_6_2_0.dtd">
<user-notification-definitions>
    <definition>
        <notification-type>${com.myproject.portal.notifications.UserNotificationHandler.PORTLET_ID}</notification-type>
        <description>receive-a-notification-when-triggered</description>
        <delivery-type>
            <name>email</name>
            <type>${com.liferay.portal.model.UserNotificationDeliveryConstants.TYPE_EMAIL}</type>
            <default>true</default>
            <modifiable>true</modifiable>
        </delivery-type>
        <delivery-type>
            <name>website</name>
            <type>${com.liferay.portal.model.UserNotificationDeliveryConstants.TYPE_WEBSITE}</type>
            <default>true</default>
            <modifiable>true</modifiable>
        </delivery-type>
    </definition>
</user-notification-definitions>
以及中的
UserNotificationHandler

project/src/main/java/com/myproject/portal/notifications 
在包
com.myproject.portal.notifications

我在
liferayportlet.xml
中编写了类似的内容:

<portlet-name>example</portlet-name>
<icon>/icon.png</icon>
<user-notification-definitions>
    user-notification-definitions.xml
</user-notification-definitions>
<user-notification-handler-class>
    com.myproject.portal.notifications.UserNotificationHandler
</user-notification-handler-class>
</portlet>
我在portlet中触发通知,如下所示:

ServiceContext serviceContext = ServiceContextFactory.getInstance(request);
                        JSONObject payloadJSON = JSONFactoryUtil.createJSONObject();
                        payloadJSON.put("userId", userId);
                        payloadJSON.put("yourCustomEntityId", 12345);
                        payloadJSON.put("additionalData", "success");

                        UserNotificationEventLocalServiceUtil.addUserNotificationEvent(userId,
                                UserNotificationHandler.PORTLET_ID,
                                (new Date()).getTime(),
                                userId,
                                payloadJSON.toString(),
                                false,
                                serviceContext);

这里有什么问题

您是否真正拥有
公共静态最终字符串PORTLET\u ID=“myportlet”在您的代码中?如果是,请注意教程中链接的额外信息:

注意:重要信息:作为通知类型使用的com.example.notificationhandler.PORTLET\u ID字符串必须与实际的PORTLET ID匹配。它实际上不需要是您的PORTLET ID,但这是正确的。原因是Notifications display portlet使用它在通知旁边显示一个小的portlet图标,以帮助用户识别通知的源。提供错误的Portlet ID或类似null的内容会导致JSP中出现难以跟踪的NullPointerException。我花了一个小时才找到它


portlet ID很可能看起来很像
“example\u WAR\u myportlet”
,这表明它部署在名为
example.WAR
的插件中,portlet ID(在portlet.xml中)是
myportlet
。如果可行,请尝试-Liferay可能需要找到portlet,以便查找、实例化和使用其NotificationHandler。(注意:这是目前的猜测-我没有尝试发布的完整代码)

在您编写的liferay-portlet.xml中

<user-notification-handler-class>
    UserNotificationHandler
</user-notification-handler-class>

用户通知处理程序
应该是:

<user-notification-handler-class>
    com.myproject.portal.notifications.UserNotificationHandler
</user-notification-handler-class>

com.myproject.portal.notifications.UserNotificationHandler
你也应该检查一下这个零件是否完好

<user-notification-definitions>
   user-notification-definitions.xml
</user-notification-definitions>

user-notification-definitions.xml

“user notification definitions.xml”文件应该在最终WAR中的WEB-INF/classes上

您的意思是liferay-portlet.xml包含两行文本而不是xml吗?@Olaf Kock No,my liferay-portlet.xml包含:example/icon.png user-notification-definitions.xml com.myproject.portal.notifications.UserNotificationHandler您可以将其编辑到问题中,将所有内容放在一个位置。目前看来这是一个很容易发现的错误,除非你阅读下面的评论。谢谢你给我们UserNotificationHandler.java的代码和创建通知的java类,好吗?@Olaf Kock好的,完成了。不,我只是试着不发布我代码的所有名称,而是给它一个更中性的名称。我在我的问题中更改了它,我希望它现在变得更清晰。liferay-portlet.xml是一个拼写错误,我在问题中更改了它。事实上,user-notification-definitions.xml在最后一场战争中位于WEB-INF/类中。然而,没有调用UserNotificationHandler方法。
<user-notification-handler-class>
    com.myproject.portal.notifications.UserNotificationHandler
</user-notification-handler-class>
<user-notification-definitions>
   user-notification-definitions.xml
</user-notification-definitions>