Fórumok

How can I get Current Group ID from model listeners

Arun R S Chandran, módosítva 8 év-val korábban

How can I get Current Group ID from model listeners

Regular Member Bejegyzések: 149 Csatlakozás dátuma: 2013.03.12. Legújabb bejegyzések
Hi All,
I'm trying to get the current groupId(basically the current site id where the user is) from user model listener public void onAfterCreate(User user).

I tried to use GroupThreadLocal but it returns me zero which is a wrong groupid. The same time I'm able to get CompanyId using CompanyThreadLocal.

Does anyone done this before any solution ot get the groupid here?

Thanks and Regards,
Arun R S
Arun R S Chandran, módosítva 8 év-val korábban

RE: How can I get Current Group ID from model listeners

Regular Member Bejegyzések: 149 Csatlakozás dátuma: 2013.03.12. Legújabb bejegyzések
Hi All,
I'm really stuck in this trouble. Is there any help to resolve this issue? emoticon
thumbnail
Jan Geißler, módosítva 8 év-val korábban

RE: How can I get Current Group ID from model listeners

Liferay Master Bejegyzések: 735 Csatlakozás dátuma: 2011.07.05. Legújabb bejegyzések
What you are trying to do is not possible. The Model Listener does not know from where a request was made.
Arun R S Chandran, módosítva 8 év-val korábban

RE: How can I get Current Group ID from model listeners

Regular Member Bejegyzések: 149 Csatlakozás dátuma: 2013.03.12. Legújabb bejegyzések
Jan Geißler:
What you are trying to do is not possible. The Model Listener does not know from where a request was made.


Jan,
Thank you for your response. I understand this point. But there should be some way to get the current Id from all the places, right?

Otherwise I need to use the GroupLocalServiceUtil to get the groupId and search with a hardcoded site name. I feel it will block me from writing a generic code which can use in all sites.

Any alternative solution for this?

Thanks and Regards,
Arun R S
thumbnail
Jan Geißler, módosítva 8 év-val korábban

RE: How can I get Current Group ID from model listeners

Liferay Master Bejegyzések: 735 Csatlakozás dátuma: 2011.07.05. Legújabb bejegyzések
Arun R S Chandran:

But there should be some way to get the current Id from all the places, right?

No. There should not. The ModelListener should only be notified that a Model changed, not from where is was edited.
What is you use case?
thumbnail
Jan Geißler, módosítva 8 év-val korábban

RE: How can I get Current Group ID from model listeners

Liferay Master Bejegyzések: 735 Csatlakozás dátuma: 2011.07.05. Legújabb bejegyzések
For cross reference:
https://www.liferay.com/de/community/forums/-/message_boards/view_message/52311531#_19_message_52237040
Arun R S Chandran, módosítva 8 év-val korábban

RE: How can I get Current Group ID from model listeners

Regular Member Bejegyzések: 149 Csatlakozás dátuma: 2013.03.12. Legújabb bejegyzések
Jan Geißler:
Arun R S Chandran:

But there should be some way to get the current Id from all the places, right?

No. There should not. The ModelListener should only be notified that a Model changed, not from where is was edited.
What is you use case?


Jan,
Thank you. My use case is on a user sign up(from registration/sign in portlet) I want to add the user to the site where the registration portlet is placed. I tried overriding the struts action for account_create. But I felt like for this simple implementation, overriding the existing code of Liferray. I'm trying to avoid such things from coding.

May I know any other flexible and easy way to solve this hurdle?

Thanks and Regards,
Arun
thumbnail
Jan Geißler, módosítva 8 év-val korábban

RE: How can I get Current Group ID from model listeners (Válasz)

Liferay Master Bejegyzések: 735 Csatlakozás dátuma: 2011.07.05. Legújabb bejegyzések
Actually you don override an action completely. You wrap it in your custom class. In your custom class you firstly call the original Action, and after that you add the user to the site.
This is a clean approach to the problem, as you will not modify the Liferay Core code, but you extend ist. This way, it should work with future versions of Liferay (if the API for adding a User to a Site does not change ;) )

We already have implemented such an approach and is it running fine in a production environment.
thumbnail
Olaf Kock, módosítva 8 év-val korábban

RE: How can I get Current Group ID from model listeners (Válasz)

Liferay Legend Bejegyzések: 6403 Csatlakozás dátuma: 2008.09.23. Legújabb bejegyzések
Go with Jan's recommendations. ModelListeners are meant to add some persistence-related stuff, not business logic. Use the fact that you can't easily get the group as a hint that you're looking at the wrong place. In the action you have everything you need available - just do what you need, remember to delegate to the original implementation. You probably want to first delegate to Liferay's implementation, then add your custom code after the account has been created.
Arun R S Chandran, módosítva 8 év-val korábban

RE: How can I get Current Group ID from model listeners

Regular Member Bejegyzések: 149 Csatlakozás dátuma: 2013.03.12. Legújabb bejegyzések
Jan and Olaf,
I understand what you meant. I was on a vacation and thus reply came late ... emoticon

This helps me a lot to implement the feature I want. And helps understanding more best practices with Hooks.

Thanks and Regards,
Arun R S