开发者

Liferay - Hook for GroupWrapper

开发者 https://www.devze.com 2023-03-07 14:23 出处:网络
I\'m trying to override the getDescriptiveName() method in com.liferay.portal.model.Group I found a wrapper (com.liferay.portal.model.GroupWrapper), so I tried to write a hook as written in the docum

I'm trying to override the getDescriptiveName() method in com.liferay.portal.model.Group

I found a wrapper (com.liferay.portal.model.GroupWrapper), so I tried to write a hook as written in the documentation :

liferay-hook.xml:

<service>
    <service-type>com.liferay.portal.model.GroupWrapper</service-type>
    <service-impl>fr.villedeniort.hook.expando.GroupWrapperImpl</service-impl>
</service>

fr.villedeniort.hook.expando.GroupWrapperImpl.java:

public class GroupWrapperImpl extends GroupWrapper {
    public GroupWrapperImpl(Group group) {
    super(group);
}

@Override
public java.lang.String getDescriptiveName()
  throws com.liferay.portal.kernel.exception.PortalException,
  com.liferay.portal.kernel.exception.SystemException {
    return super.getDescriptiveName();
}

When the hook is deployed, it raises an exception :

java.lang.NoSuchMethodException: fr.villedeniort.hook.expando.GroupWrapperImpl.<init>(com.liferay.portal.model.GroupWrapper)

I browse the code I found out that it breaks at this part for a reason I ignore:

Constructor<?> serviceImplConstructor = serviceImplClass.getConstructor(new Class<?>[] {serv开发者_运维百科iceTypeClass});

At this point, variables have theses values:

serviceType "com.liferay.portal.model.GroupWrapper" (id=14829)
serviceImpl "fr.villedeniort.hook.expando.GroupWrapperImpl" (id=14830)
serviceTypeClass Class<T> (com.liferay.portal.model.GroupWrapper) (id=14831)
serviceImplClass Class<T> (fr.villedeniort.hook.expando.GroupWrapperImpl) (id=14832)

Do you have any idea?

Thanks!


You should have also a constructor without any argument. Now you have one with constuctor arguments, but there is no pure class constructor that java searches when it makes class instance. After calling the pure constructor java then calls the argumented one.

I had similar case in some other context and this was the solution. <init> tag on the error message refers on this kind of issue.


Apparently, it's not possible to hook other classes than Services, so I had to find a different way. For my case, I hooked a JSP and wrote my own method to get the right descriptive name from the hook.

0

精彩评论

暂无评论...
验证码 换一张
取 消