Showing posts with label Model Listener in Liferay 7. Show all posts
Showing posts with label Model Listener in Liferay 7. Show all posts

Monday, 29 August 2016

How to use Model Listeners in Liferay 7 DXP

How to use Model Listeners in Liferay 7 DXP ?
As we know that in liferay 7 or DXP everything is a declared as a component/module so to add a model listener in Liferay 7 we need to define the class as a component.
We will be using the @Component class and to declare the component/module. The service class need to be defined as the ModelListener class. The service class defines the types under which to register this Component as a service.
This will allow us to define the model listener which we want to listen to.
@Component(immediate = true, service = ModelListener.class)
We will be extending the BaseModelListener class and overriding the required methods.
Below is the code that can be used to implement the model listener for User model.



If we create a new user using the create account page or from the control panel we would see that the desired model is getting called.



We can see that while a user is getting created all the model listener methods that we had overridden are getting called.

 

Copyright @ 2016 LiferayRevisited.