Learn Liferay DXP custom notification in 5 minute

Welcome to EnProwess blogs. In this post, I am going to talk about notification feature and how to create custom notification in DXP. Before we talk about notification feature in DXP, lets understand what has changed in DXP with compare to Liferay 6.2.

In Liferay 6.2,

  • There is Notification display portlet. This portlet can be used to display notification to all or specific user in portal.
  • Notification display portlet is also embedder in docbar to display number of notification waiting for user.
  • XML configuration required to define custom notifications class, notification definition etc.

In DXP,

Now let’s understand how to define custom notification in DXP. Before you start further, ensure you have following prerequisite installed/configured

Following are the steps to implement custom notification.


  1. Create module in Liferay workspace:

To create Liferay modules, Click File menu → Click New → Select Liferay Module Project. Provide appropriate name for module and click finish.


  1. Implement Custom User Notification Handler Class:

  • Create SendNotificationToUserHandler class and extends BaseUserNotificationHandler abstract class.
  • BaseUserNotificationHandler implements UserNotificationHandler interface so by extending this abstract class you will not be forced to implement all methods of UserNotificationHandler
  • UserNotificationHandler‘s job is to interpret notification events and determine to whom to deliver it. For ex. To which user and site etc.


    2.1. Now implement @Component block in SendNotificationToUserHandler and use “UserNotificationHandler” service which is registered as an OSGI Service as follow,


    2.2. Implement getBody() and getBodyTemplete() methods as follow in SendNotificationToUserHandler class,

  1. Add notifications information in database table:

You have successfully implemented custom notification class. Now its time to make notification entry in DB. Generally, this entry would be done from custom portlet based on business requirement to notify user about different events. Just to demonstrate how it works, I am adding one dummy entry in usernotificationevent table.

  • You need to add Notification in usernotificationevent table using “UserNotificationLocalServie” service. In DXP, you need to use XXXLocalService class instead of XXXLocalServiceUtil for DB operation. You may read more about it from following link, https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/finding-and-invoking-liferay-services
  • Refer following code block to understand how to make database entry for notification. You can also manually insert record in table for demo purpose,



With above steps, you have successfully implemented custom notification and made database table entry to display notification. It’s time to deploy code to see how it looks like. In my case, this custom notification is being rendered as following snapshot,

  • You will get notification intimation as follow,

  • You can see complete notification message as follow on click of user icon,

I hope this post gives idea about difference between Liferay6.2 and DXP to implement custom notification. EnProwess believed in learning and sharing. You can read different implementation approaches for DXP on our site. Keep learning!

Post by,

Zeenesh Patel

Share it :

Leave a Reply

19 Comments on "Learn Liferay DXP custom notification in 5 minute"

Notify of
avatar
Sort by:   newest | oldest
Harsh Kanakhara
Guest
Harsh Kanakhara

Can you please send the github link for this demo code ?

pallavi
Guest
pallavi

Hi ,I have requirement to implement notification on upload the file.I follows all the step but I am not getting the notification
Please Help me

pallavi
Guest
pallavi

I created Module and impalement the classes but when I depoly the module but then also it is not getting store in usernotificationevent table can you please help me

Zeenesh
Guest
Zeenesh

Hi Pallavi,
Thank you for visting the blog and comment.
Please check if there is any exception.
If you can share more details(like key code block and feature where you have implemented this), it will help me to understand the issue.
Further to this, I can share the code bundle (explained in this blog) with you if you can share your email-id.

Best Regards,
Zeenesh Patel

Nicolae
Guest
Nicolae

Hi…nice work.. Can you share your code please?..thank you

Sandhu
Guest

Hi, I have followed all the above listed instructions and created a module to show custom notifications. Its creating a record in usernotificationevent table but neither it shows the count nor the notification. Could you please help me out by sharing the the code bundle explained in this blog ? Thanks in advance!

bhagyashree
Guest
bhagyashree

Hi..could you please share the above code since we are looking for similar functionality to be implemented in our project

Tien Dat
Guest
Tien Dat

Hi, can you share your code please, my email is trash6x@gmail.com, thank you.

Maria
Guest
Maria

As Others, Can I have your code, Please…My email is mkassab_99@yahoo.com
Thanks

Duy
Guest
Duy

Hi,
Thanks for your post. It’s really useful.

Could you please share your code. my email is lonelyemerald@gmail.com.

Thanks

wpDiscuz
  • Categories

  • Recent Comments

  • Recent Post

  • Tags