Fórum

writing a hook on top of Create user functionality

Piyush Singh, modificado 9 Anos atrás.

writing a hook on top of Create user functionality

New Member Postagens: 16 Data de Entrada: 10/02/14 Postagens Recentes
Hi,

I have requirement, where I would like to execute some custom business logic after creating a user in liferay. Is the hook the best way to do it or is there some other option available. Any help with any code samples will be helpful. I am using Liferay 6.2 CE GA2
thumbnail
David H Nebinger, modificado 9 Anos atrás.

RE: writing a hook on top of Create user functionality

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
Nope. I'd use a user model listener. You can bind into the onAfterCreate() method to do something for a newly created user instance, or us onBeforeCreate() to do something with the User before it gets persisted to the database.
thumbnail
Pradeep Mishra, modificado 9 Anos atrás.

RE: writing a hook on top of Create user functionality

New Member Postagens: 10 Data de Entrada: 02/03/12 Postagens Recentes
Hi Piyush,
You can achieve this using model listener hook where you can write your custom logic in "onAfterCreate" method but i would recommend you to go with overriding the service using hook where you need to override the method you want. After calling super.methodName(...) then you can add some custom business logic.
Regards,
pradeep
Piyush Singh, modificado 9 Anos atrás.

RE: writing a hook on top of Create user functionality

New Member Postagens: 16 Data de Entrada: 10/02/14 Postagens Recentes
Thanks David and Pradeep. I'll try it out and let you know the outcome
thumbnail
David H Nebinger, modificado 9 Anos atrás.

RE: writing a hook on top of Create user functionality

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
Anytime you "override" liferay code, you're taking responsibility for managing it going forward.

Unless there is some overriding reason to override the service (and in this case I don't really see it), the hassle of overriding a Liferay service really doesn't pay off, especially when there is the perfectly capable model listener suitable for the listed requirements.

Sure, you can push in a thumbtack using a sledge hammer, but most of the time it's better just to continue using your thumb.
Piyush Singh, modificado 9 Anos atrás.

RE: writing a hook on top of Create user functionality

New Member Postagens: 16 Data de Entrada: 10/02/14 Postagens Recentes
Hi David,

My requirement is not to actually override any of liferay's code but to populate some tables in some other DB(other than liferay Demoticon as soon as the user is created.

Kind Regards,
Piyush Singh
thumbnail
David H Nebinger, modificado 9 Anos atrás.

RE: writing a hook on top of Create user functionality

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
My point was targeted at Pradeep's suggestion to override the Liferay service layer...