掲示板

Can you override a <whatever>LocalServiceImpl with a hook?

thumbnail
12年前 に Cameron McBride によって更新されました。

Can you override a <whatever>LocalServiceImpl with a hook?

Expert 投稿: 269 参加年月日: 11/02/08 最新の投稿
In particular I am looking to change some functionality in CalEventLocalServiceImpl.

I have created my class that extends CalEventLocalServiceImpl and placed this in the xml:
	<service>
    	<service-type>com.liferay.portlet.calendar.service.impl.CalEventLocalServiceImpl</service-type>
    	<service-impl>com.liferay.portlet.calendar.service.impl.HCACalEventLocalServiceImpl</service-impl>
	</service>


It bombs out when trying to register the hook. Is the only way to override functionality in a LocalServiceImpl through the ext environment?
thumbnail
12年前 に Thiago Leão Moreira によって更新されました。

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Liferay Legend 投稿: 1449 参加年月日: 07/10/10 最新の投稿
You can use a hook to override any *ServiceImpl. You made almost everything right, the wrong part was extend CalEventLocalServiceImpl instead of CalEventLocalServiceWrapper
thumbnail
12年前 に Cameron McBride によって更新されました。

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Expert 投稿: 269 参加年月日: 11/02/08 最新の投稿
So I have changed my xml to:
	<service>
    	<service-type>com.liferay.portlet.calendar.service.CalEventLocalServiceWrapper</service-type>
    	<service-impl>com.liferay.portlet.calendar.service.impl.HCACalEventLocalServiceImpl</service-impl>
	</service>


I have changed my class to extend CalEventLocalServiceWrapper. At this point I have not bothered to add any methods to the class except for the required constructor. When I deploy I get an error registering the hook:
Caused by: java.lang.NoSuchMethodException: com.liferay.portlet.calendar.service.impl.HCACalEventLocalServiceImpl.<init>(com.liferay.portlet.calendar.service.CalEventLocalServiceWrapper)</init>


I'm sure I'm overlooking something silly. Thanks for the help.
thumbnail
12年前 に Thiago Leão Moreira によって更新されました。

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Liferay Legend 投稿: 1449 参加年月日: 07/10/10 最新の投稿
Yep, we are! Try this

<service>
        <service-type>[b]com.liferay.portlet.calendar.service.CalEventLocalService[/b]</service-type>
        <service-impl>com.liferay.portlet.calendar.service.impl.HCACalEventLocalServiceImpl</service-impl>
    </service>
thumbnail
12年前 に Cameron McBride によって更新されました。

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Expert 投稿: 269 参加年月日: 11/02/08 最新の投稿
Ha, you beat me to it. I tried that as a wild guess and it indeed was the missing piece. I'm adding an option to notify the community/group about an event.

Now it's time to add some methods. My end goal is to change whats in the remindUser method of CalEventLocalServiceImpl. However that is a protected method and is not part of the Wrapper class. I assume that I am not going to be able to override that. The calling method is public, in the wrapper and is called checkEvents. I assume I'll have to copy this method and then also any private/protected methods that it may call, which would include the method I want to change. I have tested overriding checkEvents and it does get called when the event triggers, yay! I just want to make sure I go about it the best way...
thumbnail
12年前 に Sandeep Nair によって更新されました。

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Liferay Legend 投稿: 1744 参加年月日: 08/11/06 最新の投稿
One limitation it has is while copying the code from <original>localserviceimpl, you have to make sure there is nothing in it, which is from portal-impl.jar or it will again give exception

Regards,
Sandeep
thumbnail
12年前 に Cameron McBride によって更新されました。

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Expert 投稿: 269 参加年月日: 11/02/08 最新の投稿
Yeah that would be a bummer, I could use PortalClassInvoker if I had to.

What I've ran into currently is there are some other variables that checkEvent runs but don't seem available to me: calEventPersistence and userPersistence.

Update: This seems to be turning into a never ending task. If I went with an EXT plugin would I be able to copy the entire CalEventLocalServiceImpl class and include my changes? That may be way easier.

Update 2: Creating my own class that extends CalEventLocalServiceImpl, copying the one method and changing it only took a few minutes in the ext environment :-( I sure would like to use a hook for something!
thumbnail
12年前 に Sandeep Nair によって更新されました。

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Liferay Legend 投稿: 1744 参加年月日: 08/11/06 最新の投稿
Yes true. Well i am eagerly waiting for Liferay 6.1 where i can create my Struts action hook. Then what we can do is create a custom service for the same table and call the same from our struts action

Regards,
Sandeep
8年前 に Sindhu Varshini によって更新されました。

RE: Can you override a <whatever>LocalServiceImpl with a hook?

New Member 投稿: 6 参加年月日: 13/04/19 最新の投稿
Hi,

Do you have any update on the above issue. I am facing similar issue.
My requirement is to add another definition of terms in message boards. so I am trying to extend to access notifySubscribers() method from com\liferay\portlet\messageboards\service\impl\MBMessageLocalServiceImpl.java service using hook. But variables companyPersistence, groupPersistence,portletPreferencesLocalService,serviceContext are not available to me. Do we have to use EXT plugin for modifying service class? Hook doesn't work?

Can anyone share your knowledge.



Thanks,
Sindhu
thumbnail
8年前 に Sandeep Nair によって更新されました。

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Liferay Legend 投稿: 1744 参加年月日: 08/11/06 最新の投稿
Hi,

Since it is protected method, you need to write ext.

Regards,
Sandeep
thumbnail
8年前 に Olaf Kock によって更新されました。

RE: Can you override a <whatever>LocalServiceImpl with a hook?

Liferay Legend 投稿: 6398 参加年月日: 08/09/23 最新の投稿
well, you could use a hook to override every single method that calls notifySubscribers (with a copy of the original code) and change the notifySubscribers call to a new implementation. Just to provide one more option - sometimes this is prohibitive and sometimes it's a good option.
8年前 に Sindhu Varshini によって更新されました。

RE: Can you override a <whatever>LocalServiceImpl with a hook?

New Member 投稿: 6 参加年月日: 13/04/19 最新の投稿
Hi,

Thanks Everyone for your help.

Thanks,
Sindhu