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.
RELATED POSTS
RELATED POSTS
Thanks for your all posts. It helps me a lot.
ReplyDeleteFor modal listener, Do I need to create module project from IDE or Blade CLI ?
You can use any. Best you should create an API template module and create this class in that API module.
DeleteThanks a million.You made my day.
ReplyDelete