Featured post

Docker setup for Liferay 7 with MySQL

Thursday 25 August 2016

Portal events in Liferay 7


Portal events or sometimes referred as action in Liferay are of different types.
They executes on different time and a developer can choose relevant action to perform.
You can find these entries in portal.properties-

1) Servlet service event
The pre-service events process before Struts processes the request.
The post-service events process after Struts processes the request.

servlet.service.events.pre
servlet.service.events.post

2) Login Events process after successful login only.

login.events.pre
login.events.post

3) Logout events called after successful logout.

logout.events.pre
logout.events.post

In this post we will be setting landing page in Liferay 7 OSGI way with post login action.
But at the end you will explore that all of the actions can be implemented by a single change of property.

I will be adding class only in the post, you can choose build type from - Gradle/Maven

To add events you need to -
1) Implement com.liferay.portal.kernel.events.LifecycleAction
2) Add annotation
@Component(
immediate = true, property = {"key=login.events.pre"},
service = LifecycleAction.class
)

that's all, you need to do :)

Below is the code you can refer -


package com.sample;

import javax.servlet.http.HttpSession;

import org.osgi.service.component.annotations.Component;

import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.LifecycleAction;
import com.liferay.portal.kernel.events.LifecycleEvent;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.struts.LastPath;
import com.liferay.portal.kernel.util.StringPool;

@Component(
  immediate = true, property = {"key=login.events.post"},
  service = LifecycleAction.class
 )
public class LandingRedirectAction implements LifecycleAction {
 public static final Log LOGGER = LogFactoryUtil.getLog(LandingRedirectAction.class);
 @Override
 public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {
  LOGGER.info("PostLogin called");
        HttpSession session = lifecycleEvent.getRequest().getSession();
        session.setAttribute("LAST_PATH", new LastPath(StringPool.BLANK, "/web/guest/landMeOnMoon"));
 }
}


Now, in here if you want to change this action/event to be called on each page just change the property "key" to "servlet.service.events.pre" and add your code accordingly.

You are just done, Try & Enjoy the function.............:)

26 comments:

  1. Share great information about your blog , Blog really helpful for us . We read your blog , share most useful information in blog . Thanks for share your blog here .
    หนังสือ forex

    ReplyDelete

  2. Hello, do you know how to stop the logout action in the pre logout event?
    What I need is that I only continue if I send a parameter in the url, otherwise I redirect to the main page and continue with the session open.

    ReplyDelete
  3. Share great information about your blog , Blog really helpful for us

    ReplyDelete
  4. On the off chance that you have to rent a bond blender and escavator, this will just increase your solid garage cost. Chape Braspenning: Chape voor Nieuwbouw of Renovatie

    ReplyDelete
  5. The gathering could be recorded making minute taking simple. http://eddyleisure.com/stage-hire-yorkshire/

    ReplyDelete
  6. How about we start our exchange about Christmas by taking a gander at the early Church as depicted in the New Testament. Brian May Net Worth

    ReplyDelete
  7. This excellent website definitely has all of the information I needed concerning this subject and didn?t know who to ask.
    ghế gỗ giá rẻ

    ReplyDelete
  8. It’s hard to find experienced people in this particular topic, however, you seem like you know what you’re talking about! Thanks
    Xem thêm

    ReplyDelete
  9. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. forro London

    ReplyDelete
  10. As right on time as 3000 BC, the old Egyptians were the first to utilize the utilization of concrete in the structure of their pyramids.Chape

    ReplyDelete
  11. Great job for publishing such a nice article. Your article isn’t only useful but it is additionally really informative. we provide stage hire melbourne at affordable prices. for more info visit our website.

    ReplyDelete
  12. Great post, Which you have shared here. This information very important for every person those really interesting in Speaker Rental. We have a huge collection of sound instrument like D&B Audiotechnik. Visit our website for more updates!

    ReplyDelete
  13. This time, do something truly thoughtful and add personalized birthday wishes and birthday poems to your card or gift. Your friends and family will know that you really spent some time and effort, and they will appreciate how much they were in your thoughts, as you have taken the time to add a personal touch to your birthday offering for them.
    event

    ReplyDelete
  14. Most importantly, the whole event left we all stunned. What we had thought to be an association in paradise, ended up being a shocking association, an association that was never intended to be. The far-fetched event of separation had never entered our thoughts.420 events nyc

    ReplyDelete


  15. Really nice and informative blog, keep it up. Thanks for sharing and I have some suggestions.
    if you want to learn Mobile App Development(android, iOS), Join Now Mobile App Training in Bangalore.
    Visit a Website:- Android Training in Bangalore | AchieversIT
    This may help you to find something useful

    ReplyDelete
  16. . The specialists had disclosed to us that it was all around the second the growths were recognized in Jacques' mind. In case Jacques' days were numbered, mine had expected an example. music events

    ReplyDelete
  17. It was an astonishing event. Mike was so amped up for it. He and Laura coordinated his 40th birthday celebration party with spirit and panache. web-based reserved seating software

    ReplyDelete
  18. In case Jacques' days were numbered, mine had accepted an example. Each day I would go to office and each evening I would visit Jacques at the clinic before I got back.Learn about personal investments

    ReplyDelete
  19. I really like and appreciate your blog post. Much obliged.
    get more details about event company

    ReplyDelete
  20. It is amazing and wonderful to visit your site. I've learned many things from your site.
    square truss rental orlando

    ReplyDelete
  21. We proceeded with our reality in this fantastic style for quite a while. My mom was occupied with her work; I was joyfully engaged with my inspirational, instructing and guiding meetings. Deep Etiching Service

    ReplyDelete
  22. There was no change to or rest from this daily schedule. Its sheer dullness caused me to feel like a machine, as though I would go on with this drudgery even after Jacques' passing.events lineup

    ReplyDelete
  23. A home buying guide for first-time buyers with current information and calculators and every step of the buying process.Buying Your First Home in Canada

    ReplyDelete
  24. Use our Canadian Creditworthiness calculator to check your credit score and also get tips to boost your credit score. Buying Your First Home in Canada

    ReplyDelete
  25. Excellent blog!!! I really enjoy to read your post and thanks for sharing!
    Best Divorce Lawyers in Arlington VA
    Solicitation Of A Minor VA

    ReplyDelete