Total Pageviews

Sunday, October 14, 2012

Overriding Events: Working with PreActions and PostActions in Liferay using EXT

Liferay provides us facility to execute some code before and after of some specific events, namely Login, Logout and Service. Login and Logout are self-explanatory, Service is the event that takes place before or after every Action. For instance, If we have CustomServicePreAction and CustomLOginPreAction, in that case CustomServicePreAction will be called first then CustomLOginPreAction and then the LoginAction class will be invoked.
To achieve this, we need to make some entry in the portal-ext.properties, however some values are already present in portal.properties file, we have to update those properties, as following:
Here the our custom classes are: 

  1. com.liferay.portal.events.CustomServicePreAction, 
  2. com.liferay.portal.events.CustomServicePostAction, 
  3. com.liferay.portal.events.CustomLoginPreAction, 
  4. com.liferay.portal.events.CustomLoginPostAction,
  5. com.liferay.portal.events.CustomLogoutPreAction, and 
  6. com.liferay.portal.events.CustomLogoutPostAction.


Now we have to add the following classes in Ext:

1. CustomServicePreAction


2. CustomServicePostAction

3. CustomLoginPreAction

4. CustomLoginPostAction

5. CustomLogoutPreAction

6. CustomLogoutPostAction


And now, run your code. It will work.

3 comments:

  1. Hi
    we can implement CustomLoginPreAction,CustomLoginPostAction,CustomLogoutPostAction and CustomLogoutPreAction using hook.so why we need to go for EXT.correct me if i'm wrong

    ReplyDelete
    Replies
    1. Yes you are correct, but this article especially deals with EXT approach. I'm in-progress of writing an article with hooks approach too. thanks for asking.

      Delete
  2. Thanks for your blog it's really helpful, I have one doubt that what is the exact difference in post and pre login and logout event. I have some confusion, if we check for a user is login or not then any of then can be used, may be possibility some seconds of difference. Then why these two. Thanks

    ReplyDelete