留言板

writing a hook on top of Create user functionality

Piyush Singh,修改在9 年前。

writing a hook on top of Create user functionality

New Member 帖子: 16 加入日期: 14-2-10 最近的帖子
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,修改在9 年前。

RE: writing a hook on top of Create user functionality

Liferay Legend 帖子: 14916 加入日期: 06-9-2 最近的帖子
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,修改在9 年前。

RE: writing a hook on top of Create user functionality

New Member 帖子: 10 加入日期: 12-3-2 最近的帖子
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,修改在9 年前。

RE: writing a hook on top of Create user functionality

New Member 帖子: 16 加入日期: 14-2-10 最近的帖子
Thanks David and Pradeep. I'll try it out and let you know the outcome
thumbnail
David H Nebinger,修改在9 年前。

RE: writing a hook on top of Create user functionality

Liferay Legend 帖子: 14916 加入日期: 06-9-2 最近的帖子
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,修改在9 年前。

RE: writing a hook on top of Create user functionality

New Member 帖子: 16 加入日期: 14-2-10 最近的帖子
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,修改在9 年前。

RE: writing a hook on top of Create user functionality

Liferay Legend 帖子: 14916 加入日期: 06-9-2 最近的帖子
My point was targeted at Pradeep's suggestion to override the Liferay service layer...